Super Jumping! Jumping! Jumping! (最长子序列)
来源:互联网 发布:网络部咨询员提成方案 编辑:程序博客网 时间:2024/05/21 15:40
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.
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.
3 1 3 24 1 2 3 44 3 3 2 10
4103
有一种新游戏,在一条路径上有起点(start),终点(end),中间点(32位的正整数),
从起点可以跳到多个中间点,再从中间点跳到终点,但是每次跳的都必须比前一个大,
求所有可能中,经过点数字的最大和
思路:
简单的最长子序列问题,只不过 dp记录的是和,最长子序列记录的长度
状态转移方程dp【当且位置i】=max(dp【i之前所有位置】)+val【当前位置的数字】;
ps:之前位置数字均小于当前位置数字
代码:
#include<stdio.h>#include<string.h>#include<algorithm>#define MAX 1005using namespace std;long dp[MAX];//记录走到每一步可以获得的最大值long val[MAX];//记录轨道上的数字int main(){ int n; while(scanf("%d",&n)!=EOF){ if(n==0) break; memset(dp,0,sizeof(dp)); memset(val,0,sizeof(val)); int i; for(i=1;i<=n;i++) scanf("%ld",&val[i]); int j; for(i=1;i<=n;i++){ long sum=0; int bestj=0; for(j=1;j<i;j++){ //寻找已经走过的且比当前点小的点中获得的和最大的位置 if(val[j]<val[i]&&dp[j]>sum){ sum=dp[j]; bestj=j; } } dp[i]=val[i]+dp[bestj]; } long maxx=0; for(i=1;i<=n;i++) maxx=max(maxx,dp[i]); printf("%ld\n",maxx); }return 0;}
阅读全文
0 0
- Super Jumping! Jumping! Jumping! (最长子序列)
- Super Jumping! Jumping! Jumping! hdu1087 最长有序子序列
- HDU 1087 Super Jumping! Jumping! Jumping!最长上升子序列
- HDU1087 Super Jumping! Jumping! Jumping!【最长上升子序列+DP】
- hdoj--1087--Super Jumping! Jumping! Jumping!(最长上升序列)
- hdu 1087 Super Jumping! Jumping! Jumping!(最长上升子序列变形)
- Super Jumping! Jumping! Jumping!(求最长递增子序列之和)
- hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)
- HDU 1087 Super Jumping! Jumping! Jumping! (最长上升子序列和)
- Super Jumping! Jumping! Jumping! (最长上升子序列的和)
- hdu 1087 Super Jumping! Jumping! Jumping! (动态规划,求最长子序列之和)
- HDU 1087 Super Jumping! Jumping! Jumping!(dp最长上升子序列的和)
- hdu1087 Super Jumping! Jumping! Jumping!(最长上升子序列和)
- HDU 1087 Super Jumping! Jumping! Jumping! (最长上升子序列求和)【最长序列求和类模板】
- HDU 1080-Super Jumping! Jumping! Jumping!(LIS最长上升子序列-最大递增子段和)
- hdu 1087 Super Jumping! Jumping! Jumping!(dp+最长递增序列)
- HDU 1087 Super Jumping! Jumping! Jumping!(最大的上升子序列的和)(不是最长)(易混淆)
- 【最长上升子序列】HDU 1087——Super Jumping! Jumping! Jumping!
- NOIP2006普及组-数列
- Sql Server千万级分页存储过程
- oracle数据库自增序列的创建
- Struts2 笔记一
- 怎样做才是最优雅方式切换 web 项目数据源 ?
- Super Jumping! Jumping! Jumping! (最长子序列)
- hdu 6143
- Fast Matrix Calculation HDU
- 中国各地车牌
- 常用正则表达式校验
- 利用process.start()启动WinRAR.exe执行压缩命令在本地运行正常,放到服务器时WinRAR.exe也正常启动了,但没有成功完成压缩指令
- 文件系统及文件系统挂载
- I/O复用到底是什么意思
- [SDUT](2123)查找练习 hash——出现过的数字 ---哈希查找(查找)