hdoj1087Super Jumping! Jumping! Jumping!(上升序列求最大和)
来源:互联网 发布:风水罗盘软件安卓版 编辑:程序博客网 时间:2024/05/07 13:11
Problem 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.
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.
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 24 1 2 3 44 3 3 2 10
Sample Output
4103此题数据范围小,之间暴力O(n*n)即可,在最长上升序列(O(n*n))的模板上稍加修改即可代码如下:#include<cstdio>#include<cstring>#include<algorithm>#define INF 0x3f3f3f3fusing namespace std;int a[1010];int dp[1010];int n,i,j;int main(){while(scanf("%d",&n),n){for(i=1;i<=n;i++){scanf("%d",&a[i]);}int ans=-1; for(i=1;i<=n;i++) { dp[i]=a[i]; for(j=1;j<=i;j++) { if(a[j]<a[i]) { dp[i]=max(dp[i],dp[j]+a[i]);}}ans=max(ans,dp[i]);//最长上升序列的总和不一定最大,所以在这比一下. }printf("%d\n",ans);}}
0 0
- hdoj1087Super Jumping! Jumping! Jumping!(上升序列求最大和)
- hduoj Super Jumping! Jumping! Jumping!【最大上升子序列和】
- hdu 1087 Super Jumping! Jumping! Jumping!(LIS变形题,求上升子序列的最大和)
- HDU 1087 Super Jumping!Jumping!Jumping求连续上升子序列的最大和值 (解析)
- HDU 1087 Super Jumping! Jumping! Jumping!(求最大上升子序列和)
- hdu 1087 Super Jumping! Jumping! Jumping!(dp:上升子序列最大和)
- HDU-1087 Super Jumping! Jumping! Jumping!(上升子序列最大和)
- 动态规划:HDU1087-Super Jumping! Jumping! Jumping!(最大上升子序列和)
- 【HDU 1087】Super Jumping! Jumping! Jumping!(最大上升子序列和,动态规划)
- HDU 1087 Super Jumping! Jumping! Jumping!(求绝对递增子序列的最大和)
- hdu1087 Super Jumping! Jumping! Jumping! (求最大递增子序列和)
- hdoj1087Super Jumping! Jumping! Jumping!【dp】
- hdu 1087 Super Jumping! Jumping! Jumping! ( 求序列的最大上升序列 )
- (hdu step 3.2.3)Super Jumping! Jumping! Jumping!(DP:求最长上升子序列的最大和)
- hdu1087 Super Jumping! Jumping! Jumping!【最大上升子序列】
- HDU 1087 Super Jumping! Jumping! Jumping!(最大的上升子序列的和)(不是最长)(易混淆)
- HDU 1080-Super Jumping! Jumping! Jumping!(LIS最长上升子序列-最大递增子段和)
- 每日三题-Day2-C(HDU 1087 Super Jumping! Jumping! Jumping! 最大上升子序列和)
- Codeforces #367 B. Interesting drink(二分)
- 华为 oj 简单密码破解&&汽水瓶&&删除字符串中出现次数最少的字符&&字符串排序
- 类的继承和虚函数
- poj2431Expedition(贪心,优先队列)
- 10个免费在线测试网页性能工具
- hdoj1087Super Jumping! Jumping! Jumping!(上升序列求最大和)
- Go语言_LiteIDE下引用Github上的项目
- chrome浏览器默认跳转google.com而不是google.com/hk
- Qt设置密码输入框格式QLineEdit
- [LeetCode] Perfect Squares 完全平方数
- 二、Android网络框架
- 阻止关机
- 麻将
- Matrix的set,pre,post调用顺序