动态规划C++::杭电ACM1003

最后更新于:2022-04-01 09:48:03

~~~ #include <iostream> using namespace std; int main() { int T,N,i,j,a[100001],count=0; cin>>T; for (j=0;j<T;j++) { cin>>N; for (i=0;i<N;i++) cin>>a[i]; int maxSum=a[0]; int sum=0,l=0,r=0,temp=0; for (i=0;i<N;i++) { sum=sum+a[i]; if(sum>maxSum) { maxSum=sum; l=temp; r=i; } if(sum<0) { sum=0; temp=i+1; } } count++; cout<<"Case "<<count<<":"<<endl; cout<<maxSum<<" "<<l+1<<" "<<r+1<<endl; if(j<T-1) cout<<endl; } return 0; } ~~~
';