1087Super Jumping! Jumping! Jumping(寻找和最大的升序子序列)
来源:互联网 发布:生日快乐软件在线制作 编辑:程序博客网 时间:2024/06/05 08:16
题目:
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14610 Accepted Submission(s): 6143
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
题目解析:
利用动态规划解题
动态方程:
b[i]存i位置的数,dp[i]存i位置的最大和。
状态方程: dp[i]=max { dp[j](if(b[j]<b[i])) } + b[i]
代码:
#include<iostream>#include<String>#include<cmath>using namespace std;/*b[i]存i位置的数,dp[i]存i位置的最大和。状态方程: dp[i]=max { dp[j](if(b[j]<b[i])) } + b[i]*/int main(){int b[1010]={0};int dp[1010]={0};int n;while(cin>>n,n){int max;bool flag=false;for(int i=0;i<n;i++){cin>>b[i];max=-1;flag=false;for(int j=0;j<i;j++){if((b[j]<b[i])&&(dp[j]+b[i]>max)){max=dp[j]+b[i];flag=true;}}if(flag)dp[i]=max;elsedp[i]=b[i];}int s=-1;for(i=0;i<n;i++){if(dp[i]>s)s=dp[i];}cout<<s<<endl;}return 0;}
小结:
总结动态规划的题目的规律,多多练习这类题目
- 1087Super Jumping! Jumping! Jumping(寻找和最大的升序子序列)
- HDU 1087 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! (最大递增子序列和)
- hdu 1087 Super Jumping! Jumping! Jumping!(dp:上升子序列最大和)
- HDU-1087 Super Jumping! Jumping! Jumping!(上升子序列最大和)
- 【HDU 1087】Super Jumping! Jumping! Jumping!(最大上升子序列和,动态规划)
- hduoj Super Jumping! Jumping! Jumping!【最大上升子序列和】
- HDU 1087 Super Jumping! Jumping! Jumping!(最大的上升子序列的和)(不是最长)(易混淆)
- HDU 1087 Super Jumping! Jumping! Jumping!(dp最长上升子序列的和)
- hdu1087 - Super Jumping! Jumping! Jumping! (dp 求递增子序列的最大和)
- HDU1087--Super Jumping! Jumping! Jumping! (DP动态规划最大上升子序列的和)
- hdu 1087 Super Jumping! Jumping! Jumping!(上升子序列最大和)
- hdu 1087 Super Jumping! Jumping! Jumping!(基础DP,最大上升子序列和)
- HDU 1087(Super Jumping! Jumping! Jumping!)不降子序列和最大
- HDU 1087 Super Jumping! Jumping! Jumping! 最大连续子序列和
- [转载]全局变量、extern/static/const区别与联系 2011-11-28 10:08
- LayoutSubviews何时会被调用
- coredump简介与coredump原因总结
- AS3.0的类型转换
- 内存地址转换与分段
- 1087Super Jumping! Jumping! Jumping(寻找和最大的升序子序列)
- 找回不小心删除掉的存储过程!
- 在COM中使用数组参数-SafeArray[转载/修改] 2011-11-29 15:02
- 设置中的Preferencescreen应用
- 在Spring中使用quartz
- 子线程中如何调用对话框的变量和函数 2011-11-29 15:05
- C#RichTextBox的 RichTextBox.Focus();rtbLog.AppendText(msg);ReadOnly
- 分配和释放 BSTR 的内存 2011-12-1 10:19
- 什么是堆、栈? fr net