DP。
代码如下:
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 5 using namespace std; 6 7 int main() 8 { 9 int T, n, i, a, sum; 10 int k, t, x, y, maxn; 11 cin >> T; 12 for (k=1; k<=T; k++) 13 { 14 t=1; 15 sum=0; 16 maxn=-1000; 17 cin >> n; 18 for (i=1; i<=n; i++) 19 { 20 cin >> a; 21 sum+=a; 22 if (sum > maxn) 23 { 24 maxn=sum; 25 x=t; 26 y=i; 27 } 28 if (sum < 0) 29 { 30 sum=0; 31 t=i+1; 32 } 33 } 34 printf("Case %d:\n", k); 35 printf("%d %d %d\n", maxn, x, y); 36 if (k != T) 37 cout << endl; 38 } 39 return 0; 40 }