同poj2479几乎一致。。
http://www.cnblogs.com/yzcstc/archive/2013/03/23/2977529.html
1 /* 2 Author:yzcstc 3 State:Accept 4 Time:2013.2.26 5 */ 6 #include <iostream> 7 #include <cstdlib> 8 #include <cstdio> 9 #include <cmath> 10 #include <cstring> 11 #include <string> 12 #include <algorithm> 13 using namespace std; 14 const int minn = -500000001; 15 int T , n , a[100005], lsum[3][100005], rsum[3][100005] , ans; 16 17 void dp(){ 18 ans = minn; 19 lsum[0][0] = lsum[1][0] = minn; 20 rsum[0][n + 1] = rsum[1][n + 1] = minn; 21 for (int i = 1; i <= n; ++i) 22 { 23 scanf("%d",&a[i]); 24 lsum[0][i] = max(lsum[0][i - 1] + a[i] , a[i]); 25 lsum[1][i] = max(lsum[1][i - 1] , lsum[0][i - 1]); 26 } 27 28 for (int i = n; i >= 1; --i) 29 { 30 31 rsum[0][i] = max(rsum[0][i + 1] + a[i] , a[i]); 32 rsum[1][i] = max(rsum[1][i + 1] , rsum[0][i + 1]); 33 } 34 for (int i = 2; i <= n; ++i) 35 ans = max( ans , 36 max(lsum[0][i - 1], lsum[1][i - 1]) + max( rsum[0][i] , rsum[1][i])); 37 } 38 39 int main(){ 40 freopen("poj2593.in","r",stdin); 41 freopen("poj2593.out","w",stdout); 42 scanf("%d",&n); 43 while (n) 44 { 45 dp(); 46 printf("%d\n",ans); 47 scanf("%d",&n); 48 49 } 50 fclose(stdin); fclose(stdout); 51 }