Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17687 Accepted Submission(s): 7828
6 -2 11 -4 13 -5 -2 10 -10 1 2 3 4 -5 -23 3 7 -21 6 5 -8 3 2 5 0 1 10 3 -1 -5 -2 3 -1 0 -2 0
20 11 13 10 1 4 10 3 5 10 10 10 0 -1 -2 0 0 0Huge input, scanf is recommended.HintHint
代码:
#include <iostream> #include <stdio.h> #include <algorithm> #include <string.h> using namespace std; const int maxn=10003; const int inf=0x7fffffff; int num[maxn]; int n; int main() { while(scanf("%d",&n)!=EOF&&n) { for(int i=1;i<=n;i++) scanf("%d",&num[i]); int start,end,s,e,sum,maxx; start=end=s=e=1; sum=0;maxx=-inf; for(int i=1;i<=n;i++) { e=i; sum+=num[i]; if(sum>maxx) { start=s; end=e; maxx=sum; } if(sum<0) { sum=0; s=i+1; } } if(maxx<0) printf("%d %d %d\n",0,num[1],num[n]); else printf("%d %d %d\n",maxx,num[start],num[end]); } return 0; }
[ACM] hdu 1231 最大连续子序列 (动规复习),布布扣,bubuko.com
原文地址:http://blog.csdn.net/sr_19930829/article/details/24903935