Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 42367 Accepted Submission(s): 19198
水一下博客。
代码:
1 //HDU 1231.最大连续子序列-dp+位置标记 2 #include<bits/stdc++.h> 3 using namespace std; 4 typedef long long ll; 5 const int maxn=1e4+10; 6 const int inf=0x3f3f3f3f; 7 8 int a[maxn]; 9 10 int main() 11 { 12 int n; 13 while(~scanf("%d",&n)&&n!=0){ 14 for(int i=1;i<=n;i++){ 15 scanf("%d",&a[i]); 16 } 17 int pos,maxx=a[1],l=a[1],r=a[1],cnt=0; 18 for(int i=1;i<=n;i++){ 19 if(cnt<0){ 20 pos=a[i]; 21 cnt=a[i]; 22 } 23 else{ 24 cnt+=a[i]; 25 } 26 if(cnt>maxx){ 27 maxx=cnt; 28 l=pos; 29 r=a[i]; 30 } 31 } 32 if(maxx<0){ 33 cout<<0<<" "<<a[1]<<" "<<a[n]<<endl; 34 } 35 else{ 36 cout<<maxx<<" "<<l<<" "<<r<<endl; 37 } 38 } 39 }
原文:https://www.cnblogs.com/ZERO-/p/10679738.html