hdu 1231 最大连续子序列(dp)
http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=17322
裸最大连续子序列 竟然差点拿来当区间dp来做= =
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #include<algorithm> using namespace std; #define INF 1000000000 int num[10000+100]; int main() { int n,add; int i,j,k; int l,r,ans; while(scanf("%d",&n),n) { ans=-INF;l=1;r=1; int flag=0; for(i=1;i<=n;i++) { scanf("%d",&num[i]); if(num[i]>=0) flag++; } if(flag==0) { printf("0 %d %d\n",num[1],num[n]); continue; } int sum=0; int tl=1,tr=1; for(i=1;i<=n;i++) { sum+=num[i]; if(sum<0) { sum=0; while(num[i+1]<0) i++; tl=i+1; } else if(sum>ans) { ans=sum; r=i; l=tl; } } printf("%d %d %d\n",ans,num[l],num[r]); } return 0; }