HDOJ 1003 Max Sum
2011-10-07 23:19
351 查看
一维度的动态规划题目,只需要一个临时变量记录当前最大值即可。起始点与终点的记录算是很巧妙,增加两个变量达到目的。
View Code
View Code
#include <stdio.h> int main() { //freopen("Max Sum.txt","r",stdin); int num; scanf("%d",&num); for(int i=1;i<=num;i++) { int cnt; scanf("%d",&cnt); int end=0,current=0,value,temp=1,start=0,max=-1001;//最小值,Wrong Answer仅仅因为如此 for (int j=1;j<=cnt;j++) { scanf("%d",&value); current+=value; if(current>=max) { max=current; start=temp; end=j; } if(current<0) { current=0; temp=j+1; } } printf("Case %d:\n%d %d %d\n",i,max,start,end); if (i!=num) { printf("\n"); } } return 0; }
相关文章推荐
- HDOJ 1003 Max Sum
- DP专题2 HDOJ 1003 Max Sum
- HDOJ 1003 Max Sum(动态规划)
- HDOJ 1003 Max Sum
- HDOJ(1003) Max Sum
- HDOJ 1003 Max Sum(动态规划)
- HDOJ 1003 Max Sum
- HDOJ1003:Max Sum
- HDOJ_1003_Max Sum
- Hdoj 1003 Max Sum
- hdoj 1003 Max Sum【dp】
- HDOJ 1003 Max Sum
- HDOJ 1003 Max Sum
- HDOJ 1003 Max Sum
- HDOJ 1003 Max Sum
- HDOJ 1003 Max Sum参考程序
- HDOJ 1003 Max Sum(动态规划)
- HDOJ 1003 Max Sum
- HDOJ 1003.Max Sum 答案
- hdoj 1003 Max Sum