hdu-1087 Super Jumping! Jumping! Jumping! [最大递增子段和]
2016-03-09 19:33
441 查看
E - Super Jumping! Jumping! Jumping!
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
SubmitStatus
Description
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.
![](http://7xjob4.com1.z0.glb.clouddn.com/b69a36fbfe92ef60e13d861294653386)
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In
the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping
can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his
jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.
Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each case, print the maximum according to rules, and one line one case.
Sample Input
Sample Output
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
SubmitStatus
Description
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In
the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping
can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his
jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.
Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 2 4 1 2 3 4 4 3 3 2 1 0
Sample Output
4 10 3
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX_SZIE 1010 int dp[MAX_SZIE]; int val[MAX_SZIE]; int find_max(int a,int b) { return a>b?a:b; } int main() { int n; while(~scanf("%d",&n)) { if(n==0) break; for(int i=0;i<n;++i) scanf("%d",val+i); dp[0]=val[0]; int max=dp[0]; for(int i=1;i<n;++i) { dp[i]=val[i]; for(int j=i-1;j>=0;--j) if(val[i]>val[j]) dp[i]=find_max(dp[i],dp[j]+val[i]); max=find_max(max,dp[i]); } printf("%d\n",max); } return 0; }
相关文章推荐
- NYOJ-104最大和(动归题)及连续最大和核心
- 【POJ 2942】Knights of the Round Table(双联通分量+染色判奇环)
- poj 3478 The Stable Marriage Problem 稳定婚姻问题
- 反射的结果中排除隐藏的成员
- iOS 如何选择delegate、notification、KVO
- 3月7日学习笔记
- swift中的枚举个例和switch个例
- odoo could not execute command lessc
- 关于引用的一些理解
- 查看工程中图片资源大小,是否使用
- 我们用django做的产品
- 阻塞IO和非阻塞IO的区别
- 高项2016-03-07
- swift中数组的一些操作
- 如何使用Hadoop的DistributedCache
- 从最大子列和问题体会算法
- Html学习笔记(3)-Html标签(2)
- Linux环境下,在不停止程序的情况下,更换动态链接库
- 无法连接到SQL数据库
- HDU2795线段树之单点更新