标签:des style http color java os strong io
6 -2 11 -4 13 -5 -2 10 -10 1 2 3 4 -5 -23 3 7 -21 6 5 -8 3 2 5 0 1 10 3 -1 -5 -2 3 -1 0 -2 0
20 11 13 10 1 4 10 3 5 10 10 10 0 -1 -2 0 0 0Huge input, scanf is recommended.HintHint
HDU1003 max sum一样的题。。水。。
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<stdlib.h> #include<vector> #include<queue> #include<cmath> using namespace std; const int maxn = 100000 + 50; int n; int a[maxn]; int start; int last; int temp; int ans; int sum; int t; int main() { while(scanf("%d", &n)==1&&n) { t = 0; memset(a, 0, sizeof(a)); for(int i=1; i<=n; i++) { scanf("%d", &a[i]); if(a[i]<0) t++; } if( t==n ){printf("0 %d %d\n", a[1], a[n]);continue;} start = 1; last = 1; temp = 1; sum = a[1]; ans = a[1]; for(int i=2; i<=n; i++) { if( sum<0 ) { temp = i; sum = 0; } sum += a[i]; if( sum>ans ) { ans = sum; start = temp; last = i; } } printf("%d %d %d\n", ans, a[start], a[last]); } return 0; }
HDU 1231:最大连续子序列(DP),布布扣,bubuko.com
标签:des style http color java os strong io
原文地址:http://blog.csdn.net/u013487051/article/details/38302289