线性时间求解最大子序列和——HDU1003

来源:互联网 发布:大六壬排盘软件 哪个好 编辑:程序博客网 时间:2024/05/02 06:10
Problem Description
Givena sequence a[1],a[2],a[3]......a[n], your job is to calculate the maxsum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum inthis sequence is 6 + (-1) + 5 + 4 = 14.
 

 

Input
Thefirst line of the input contains an integer T(1<=T<=20) whichmeans the number of test cases. Then T lines follow, each line startswith a number N(1<=N<=100000), then N integers followed(all theintegers are between -1000 and 1000).
 

 

Output
Foreach test case, you should output two lines. The first line is "Case#:", # means the number of the test case. The second line containsthree integers, the Max Sum in the sequence, the start position of thesub-sequence, the end position of the sub-sequence. If there are morethan one result, output the first one. Output a blank line between twocases.
 

 

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








原创粉丝点击