Problem descriptiongiven 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.
Inputthe 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 ).
Outputfor 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
25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5
Sample output
Case 1 4 case 1 6A simple question is to find the sum of the maximum continuous subsequences in a sequence and output the starting and ending points of the sequence because DP has been put for a long time ..# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; int Q [100001]; int main () {int m, n, I, j, s; int sum, Max, a, B; int t; int start, end; scanf ("% d", & T); For (int K = 1; k <= T; k ++) {If (K! = 1) cout <Endl; scanf ("% d", & M); for (I = 0; I <m; I ++) scanf ("% d ", & Q [I]); sum = Q [0]; max = Q [0]; A = 0, B = 0; Start = 0; end = 0; // initialize for (I = 1; I <m; I ++) {If (sum <0) // similar to greedy ideas, when the sum is less than 0, if you want a continuous sequence, do not {A = I; B = I; sum = Q [I];} else {sum = sum + Q [I]; B = I;} If (sum> MAX) // update the maximum value {max = sum; Start = A; end = B ;}} each time ;}} cout <"case" <k <':' <Endl; cout <max <''<start + 1 <'' <End + 1 <Endl;} return 0 ;}