早教吧 育儿知识 作业答案 考试题库 百科 知识分享

ACMMAXSUM这个题目是什么意思,我竟然看不懂Givenasequencea[1],a[2],a[3]......a[n],yourjobistocalculatethemaxsumofasub-sequence.Forexample,given(6,-1,5,4,-7),themaxsuminthissequenceis6+(-1)+5+4=14.Inp

题目详情
ACM MAX SUM这个题目是什么意思,我竟然看不懂
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

Author
Ignatius.L

Recommend
We have carefully selected several similar problems for you: 1176 1087 1069 2084 1058

























▼优质解答
答案和解析
给定的序列a[1],a[2],a[3]......a[n],你的工作是计算最大和的一个子序列。例如,给定( 6, -1,5,4 ,-7 ) ,在这个序列中的最大总和是6 + (-1) + 5 + 4 = 14 。
输入
输入的第一行包含一个整数T( 1 <= T < = 20 )表示的多个测试案例。那么下面的T行,每行开头的一个数N( 1 <= N < = 100000 ) ,然后跟着N个整数( -1000和1000之间的所有整数)。
输出
对于每个测试的情况下,你应该输出两行。第一行是"Case #:",#表示测试情况的数目。第二行包含三个整数,最大和序列中,子序列的开始位置,结束位置的子序列。如果有一个以上的结果,输出的第一个。两种情况之间输出一个空行。
样本输入
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
样本输出
Case 1:
14 1 4
Case 2:
7 1 6
作者
Ignatius.L
建议
我们为您精心挑选了几个类似的问题:1176 1087 1069 2084 1058