Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17906 Accepted Submission(s): 5864
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 #define inf 999999999 6 //using namespace std; 7 const int MAX = 1000005; 8 int max(int a,int b) 9 { 10 return a>b?a:b; 11 } 12 int a[MAX]; 13 int left[MAX]; 14 int right[MAX]; 15 int main() 16 { 17 int n,m,i,j; 18 while(scanf("%d%d",&m,&n)!=EOF) 19 { 20 memset(a,0,sizeof(a)); 21 memset(left,0,sizeof(left)); 22 memset(right,0,sizeof(right)); 23 for(i=1;i<=n;i++) 24 scanf("%d",&a[i]); 25 long long count; 26 for(i=1;i<=m;i++) 27 { 28 count=-inf; 29 for(j=i;j<=n;j++) 30 { 31 left[j]=max(left[j-1],right[j-1])+a[j]; 32 right[j-1]=count; 33 if(left[j]>count) 34 count=left[j]; 35 } 36 } 37 printf("%I64d\n",count); 38 } 39 return 0; 40 }
HDU 1024 Max Sum Plus Plus (最大和子序列增强版)
原文:http://www.cnblogs.com/caterpillarofharvard/p/4234697.html