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
求子串相加最大为多少以及子串开始和结束的位置
位置从1开始
求和,每次相加和之前最大的比较,如果更大记录位置
再与0比较,如果比0小,重新开始加
#include <stdio.h>
int main(

该问题要求求解给定序列中子序列的最大和以及该子序列的起始和结束位置。输入包含测试用例数量T,每个用例有N个整数,范围在-1000到1000之间。输出应显示每个测试用例的编号、最大子序列和、子序列起始和结束位置。当有多个最大和的子序列时,输出第一个。
最低0.47元/天 解锁文章
2215

被折叠的 条评论
为什么被折叠?



