`
hulunberbus
  • 浏览: 858198 次
文章分类
社区版块
存档分类
最新评论

hdu 1003 Max Sum 动态规划

 
阅读更多

Max Sum

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 66583Accepted Submission(s): 15239


Problem Description
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.

Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).

Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.


Sample Input
2 5 6 -1 5 4 -7 7 0 6 -1 1 -6 7 -5


Sample Output
Case 1: 14 1 4 Case 2: 7 1 6

DP 动态规划的题。这道题很久以前就看过 ,那个时候还不知道什么动态规划, 用暴力求解 , 总是TLE。 今天从算法书上看了点动态规划的知识。终于顺利 把此题AC了。但过程还是花了很久。 因为我一直把 最大子序列的和 maxsum 初值定为 0 , 没考虑全为负数! 关于DP,今晚刚开始看,所以还需要点时间。 这道题 思路写在注释中。


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics