转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents
题目链接:http://poj.org/problem?id=2593
Description
Input
Output
Sample Input
5 -5 9 -5 11 20 0
Sample Output
40
代码如下:
#include <iostream> using namespace std; #define INF 0x3fffffff #define M 100000+17 int a[M],b[M]; int main() { int n,i; while(cin >> n && n) { int sum = 0, MAX = -INF; for(i = 1; i <= n; i++) { cin >> a[i]; sum+=a[i]; if(sum > MAX) { MAX = sum; } b[i] = MAX; if(sum < 0) { sum = 0; } } MAX = -INF; sum = 0; int ans = MAX, t; for(i = n; i > 1; i--) { sum+=a[i]; if(sum > MAX) { MAX = sum; } t = MAX + b[i-1]; if(t > ans) { ans = t; } if(sum < 0) { sum = 0; } } cout<<ans<<endl; } return 0; }
poj2593 Max Sequence(求两个不相交最大字段和),布布扣,bubuko.com
poj2593 Max Sequence(求两个不相交最大字段和)
原文地址:http://blog.csdn.net/u012860063/article/details/37728869