DP课题2 HDOJ 1003 Max Sum
DP专题2 HDOJ 1003 Max Sum传送门:http://acm.hdu.edu.cn/showproblem.php?pid1003Max SumTime Limit: 20
DP专题2 HDOJ 1003 Max Sum
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1003
Max Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 81597 Accepted Submission(s): 18767
Problem DescriptionInputOutputSample InputSample OutputAuthor/*Memory: 1768 KB Time: 31 MS Language: GCC Result: Accepted This source is shared by hust_lcl*/#include <stdio.h>#include <stdlib.h>int input[100010];int temp[100010];int px[100010];int py[100010];int main(){ int n , m , i , flag , k = 1 , j; scanf("%d",&n); while(n--) { scanf("%d",&m); for(i = 1 ; i <= m ; i ++) scanf("%d",&input[i]); printf("Case %d:\n",k++); temp[1] = input[1]; px[1] = 1; py[1] = 1; for(i = 2 ; i <= m ; i ++ ) { if(temp[i-1]>=0) { temp[i] = input[i] + temp[i-1]; px[i] = px[i-1]; py[i] = i; } else { temp[i] = input[i]; px[i] = i ; py[i] = i; } } flag = temp[1]; j = 1; for(i = 1 ; i <= m ; i++) if(temp[i] > flag) { flag = temp[i]; j = i; } printf("%d %d %d\n",flag, px[j],py[j]); if(n>0) printf("\n"); } return 0;}