NYOJ-44 简单DP

View Code
 1 #include<stdio.h>
2 #include<stdlib.h>
3
4 int main()
5 {
6 int i, j, ncases, n;
7 int a,b,sum;
8 scanf("%d",&ncases);
9 while( ncases-- )
10 {
11 b=-1, sum = -9999; //其中的值会有负数,所以b,sum要先设负值
12 scanf("%d",&n);
13 for(i=1; i<=n; i++)
14 {
15 scanf("%d",&a);
16 if(b >= 0)
17 b += a;
18 else
19 b = a;
20 if(b > sum)
21 sum = b;
22 }
23 printf("%d\n", sum);
24 }
25 system("pause");
26 return 0;
27 }

你可能感兴趣的:(dp)