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至于这题和hdu 1003那简直是就一题。。简单dp,做了1003后,做这题简直是so easy啦,直接代码#include <stdio.h> int main() { int n ; while(scanf("%d",&n)!= EOF && n) { int ans = 0 , sum = 0 , first = 0 , last = 0 , start=0 , end=0 ; int flag = 0 , head , tail; for(int i = 0 ; i < n ; ++i) { int temp ; scanf("%d",&temp) ; if(temp<0) { if(i == 0) { head = temp ; } if(i == n-1) { tail = temp ; } ++flag ; } if(sum == 0 && temp >= 0 ) { start = temp ; } sum += temp ; if(sum>ans) { ans = sum ; last = temp ; first = start ; } if(sum<0) { sum = 0 ; } } if(flag!=n) printf("%d %d %d\n",ans,first,last) ; else printf("%d %d %d\n",ans,head,tail) ; } return 0 ; }
原文地址:http://blog.csdn.net/lionel_d/article/details/43636809