Solution:
The dynamic programming method is used to solve the maximum subcolumn sum. Corresponding to input data a [I], there will be data DP [I]. Each element DP [I] in the array DP represents the maximum continuous subcolumn and ending with a [I. Traverse the DP array to find the child column and maximum value.
If (DP [I-1]> = 0 ){
DP [I] = DP [I-1] + A [I];
}
Else {
DP [I] = A [I]
}
#include <iostream>#include <stdio.h>#include <stdlib.h>using namespace std;int r[100001];int main(){ //freopen("in.txt","r",stdin); int cs; r[0] = -1000000; scanf("%d",&cs); int n; for(int t=1;t<=cs;t++){ scanf("%d",&n); int s=0,e=0,m=-1000000; int a,b,tmp; for(int i=1;i<=n;i++){ scanf("%d",&r[i]); if(r[i-1]>=0){ r[i]+=r[i-1]; b=i; tmp = r[i]; } else{ a = b = i; tmp = r[i]; } if(tmp>m){ m = tmp; s = a; e = b; } } if(t!=1){ printf("\n"); } printf("Case %d:\n%d %d %d\n",t,m,s,e); } //system("pause"); return 0;}