动态规划:Super Jumping! Jumping! Jumping!
来源:互联网 发布:hashmap的hash算法 编辑:程序博客网 时间:2024/06/05 06:19
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
思路:
这道题是要求最大非连续递增数字和,采用的是一种动规的思想,dp[i]保留的是前i项的最大和,然而,这道题
做起来就是那么简单,就像最长单调递增子序列,比较一下大小,加上限制条件,举个例子吧
样例: 4 1 4 3 5 输出结果是10而不是9;当然,这傻子也看得出来,这时候,你就要想一下刚才你是怎么
瞬间把他们比较出来的,因为在第四项,5+1+4>5+1+3,这时候,这道题的思想就出来了,
如果dp[i]>dp[j]+a[i](j永远小于i),那就不用更新dp[i]的值,相反,需要更新,因为dp[i]保留的是前i项
的最大和。
因为本博主才学尚浅,所以在下对动规的理解是,只要你找到了其中一步,再加上初始化,写出动态转移方程
,基本上就可以解决了。(勿喷小弟我)。。。
代码:
#include<stdio.h> int a[1003],dp[1004];int main(){ int n; while(~scanf("%d",&n)&&n) { for(int i=0; i<n; i++) { scanf("%d",&a[i]); dp[i]=a[i];//给dp[i]赋初值 } int maxx=a[0]; for(int i=0;i<n;i++) { for(int j=0;j<i;j++) { if(a[i]>a[j]&&dp[j]+a[i]>dp[i]) dp[i]=dp[j]+s[i]; } if(dp[i]>maxx) maxx=dp[i]; } printf("%d\n",maxx); }}
0 0
- HDU1087 Super Jumping! Jumping! Jumping! 动态规划
- Super Jumping! Jumping! Jumping!(动态规划)
- 动态规划 Super Jumping! Jumping! Jumping!
- 动态规划:Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping! 动态 规划
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划)
- hdu 1087 Super Jumping! Jumping! Jumping! 动态规划
- HDU 1087 Super Jumping! Jumping! Jumping! -- 简单动态规划
- 【练习09】简单动态规划 1003 Super Jumping! Jumping! Jumping!
- hdu1087 Super Jumping! Jumping! Jumping!(简单动态规划)
- 动态规划入门——Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping! (动态规划)
- 动态规划—杭电1087 Super Jumping! Jumping! Jumping!
- [ACM] hdu 1087 Super Jumping! Jumping! Jumping! (动态规划)
- HDOJ 题目1087Super Jumping! Jumping! Jumping!(动态规划)
- HDU 1087 Super Jumping! Jumping! Jumping! 动态规划
- hdoj 1087 Super Jumping! Jumping! Jumping!(动态规划)
- HDU 1087 Super Jumping! Jumping! Jumping!(动态规划)
- sql case when then end 用法
- Builds different channels of code in Android Studio and Eclipse.
- 17 - 03 - 29 图解HTTP(33)
- Linux-系统更新后启动异常
- codeforces 757 A. Gotta Catch Em' All!
- 动态规划:Super Jumping! Jumping! Jumping!
- AWS EC2 CentOS release 6.5 部署zookeeper、kafka、dubbo
- 微信小程序实例:编写tabBar模板
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B. Bash's Big Day(分拆素因子+求最多的公因子)
- 合并内容相同的单元格
- Spring 4MVC框架下在后台解析JSON数据
- linux-搭建web服务器系列--搭建mysql数据库(二)
- 滤波器的阶数
- Lua——分类目录