@ 连续子序列最大和
http://acm.hdu.edu.cn/showproblem.php?pid=1003
1 #include <iostream> 2 using namespace std; 3 int main(){ 4 int t, n; 5 cin >> t; 6 for(int i = 1; i <= t; i++){ 7 if(i != 1) cout<<endl; 8 cin >> n; 9 int lx = 1, rx, l = 1, sum = 0, ma = -9999999, x; 10 for(int j = 1; j <= n; j++){ 11 cin >> x; 12 sum += x; 13 if(sum > ma){ 14 ma = sum; 15 lx = l; 16 rx = j; 17 } 18 if(sum < 0){ 19 sum = 0; 20 l = j + 1; 21 } 22 } 23 cout<<"Case "<<i<<":"<<endl; 24 cout << ma << " " << lx << " "<<rx<<endl; 25 } 26 return 0; 27 }
只有不断学习才能进步!