- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
動态规划专题
Max Sum
Time Limit : 2000/1000ms (Java/Other)???Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 42???Accepted Submission(s) : 20
Font:?Times New Roman?|?Verdana?|?Georgia
Font Size:?←?→
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
Author
Ignatius.L
max?sum?/showproblem.php?pid=1003?????同上,最大连续子序列????????
#includestdio.h
#define min int sta,end;
int main()
{
int n,i,j,t,sum,maxsum,in,b;
scanf(%d,n);
for(i=0;in;i++)
{
sum=0;maxsum=min;sta=0;
scanf(%d,t);
for(b=j=0;jt;j++)
{
scanf(%d,in);
sum+=in;
if(summaxsum)
{
maxsum=sum;
end=j;
sta=b;
}
if(sum0)
{
sum=0;
b=j+1;
}
}
printf(Case %d:\n%d %d %d\n,i+1,maxsum,sta+1,end+1);
if(i!=n-1) printf(\n);
}
return 0;
}
///////////////////////////////////////////////////
#include?iostreamusing?namespace?std;int?main(){????int?T,N,num,start,end;????cinT;????for(int?k=0;kT;k++)????{???
文档评论(0)