hdu 1003 Max Sum

DP可以这里给出非DP程序

  题目传送门

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int t,n,i,max,m,sum,ki,kj,k,a,b;
 5     scanf("%d",&t);
 6     for(k=1;k<=t;k++)
 7     {
 8         scanf("%d",&n);
 9         max = -1000;         //两个初始化成-1000
10         sum = -1000;         //注意sum的初始化,后来见到刘汝佳书上,sum= a[0],也就是第一个数
11         a = b = 1;
12         ki = kj = 1;
13         for(i=1;i<=n;i++)
14         {
15             scanf("%d",&m);
16             if(sum>=0)
17             {
18                 kj++;
19                 sum += m;
20             }
21             else
22             {
23                 ki = i;
24                 kj = i;
25                 sum = m;
26             }
27             if(max<sum) 
28             {
29                 max = sum;
30                 a = ki;
31                 b = kj;
32             }
33         }
34         if(k==1) printf("Case %d:\n%d %d %d\n",k,max,a,b);
35         else printf("\nCase %d:\n%d %d %d\n",k,max,a,b);
36     }
37     return 0;
38 }

 

posted @ 2013-05-11 21:26  飞向梦  阅读(151)  评论(0编辑  收藏  举报