Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5591 Accepted Submission(s): 2134
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思路:简单的DP问题代码如下:#include <stdio.h> #include <limits.h> int main() { int n,i,sum,max,temp,f,l; int a[10005]; bool flag; while(scanf("%d",&n),n) { flag=false; for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]>=0) flag=true; } if(flag) { temp=l=a[0]; sum=0; max=INT_MIN; for(i=0;i<n;i++) { sum+=a[i]; if(max<sum) { max=sum; f=temp; l=a[i]; } if(sum<0) { sum=0; if(i!=n-1) temp=a[i+1]; } } printf("%d %d %d/n",max,f,l); } else { printf("0 %d %d/n",a[0],a[n-1]); } } return 0; }