hdu1231 最大连续子序列
#include<stdio.h> #include<string.h> #define maxn 10010 int a[maxn],dp[maxn]; int main() { int n,i,j,max,flag,l,r,fl; while(scanf("%d",&n)!=EOF) { if(n==0) break; flag=0; memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++) { scanf("%d",&a[i]); if(a[i]>=0) flag=1; } max=-99999999; l=r=fl=1; for(i=1;i<=n;i++) { if(dp[i-1]+a[i]>=a[i]) { dp[i]=dp[i-1]+a[i]; } else { fl=i; dp[i]=a[i]; } if(dp[i]>max) { l=fl; r=i; max=dp[i]; } } if(!flag) printf("0 %d %d\n",a[1],a[n]); else printf("%d %d %d\n",max,a[l],a[r]); } }