标签:
1 5 1 2 -1 3 -2
5
1 2 #include<iostream> 3 #include<algorithm> 4 #include<cstdio> 5 #include<cstring> 6 using namespace std; 7 const int MAXN = 1000000; 8 int dp[MAXN],a[MAXN]; 9 int main() 10 { 11 int i,j,n,T,max; 12 cin>>T; 13 while(T--) 14 { 15 cin>>n; 16 for(i=0;i<n;i++) 17 scanf("%d",&a[i]); 18 //memset{dp,0,sizeof(dp)}; 19 max=dp[0]=a[0]; 20 for(i=1;i<n;i++) 21 { 22 if(dp[i-1]>0) 23 dp[i]=dp[i-1]+a[i]; 24 else 25 dp[i]=a[i]; 26 if(dp[i]>max) 27 max=dp[i]; 28 } 29 cout<<max<<endl; 30 } 31 return 0; 32 }
标签:
原文地址:http://www.cnblogs.com/caterpillarofharvard/p/4228617.html