hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 47017 Accepted Submission(s): 21736
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.
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
分析:
①、动态规划(局部最优问题 ==> 全局最优)
②、状态方程:dp[i] = max(dp[i], dp[j] + A[i])
步骤:
①、从左到右依次遍历考虑该点的前面所有情况
②、通过状态方程 dp[i] = max(dp[i], dp[j] + A[i]) 计算该对应点的局部最优
③、通过局部最优 ==> 推出全局最优
核心代码:
for(int i = ; i < n; ++ i)
{
dp[i] = A[i];
for(int j = ; j < i; ++ j)
{
if(A[j] < A[i]) dp[i] = max(dp[i], dp[j] + A[i]);
}
my_max = max(my_max, dp[i]);
}
C/C++代码实现(AC):
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <map>
#include <queue> using namespace std;
const int MAXN = ;
long long A[MAXN], dp[MAXN], my_max; int main()
{
int n;
while(~scanf("%d", &n), n)
{
memset(dp, , sizeof(dp));
my_max = -0x3f3f3f3f;
for(int i = ; i < n; ++ i)
scanf("%d", &A[i]); for(int i = ; i < n; ++ i)
{
dp[i] = A[i];
for(int j = ; j < i; ++ j)
{
if(A[j] < A[i]) dp[i] = max(dp[i], A[i] + dp[j]);
}
my_max = max(my_max, dp[i]);
}
printf("%lld\n", my_max);
}
return ;
}
hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)的更多相关文章
- HDU 1087 Super Jumping! Jumping! Jumping
HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...
- HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 20 ...
- HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)
Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!&quo ...
- hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 ------------------------------------------------ ...
- DP专题训练之HDU 1087 Super Jumping!
Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...
- hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1087 Super Jumping! Jumping! Jumping! (DP)
C - Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
随机推荐
- SpringMVC4拦截器配置遇到的坑
目的:对get请求添加token验证(若为post请求可通过RequestBodyAdvice实现). 情景:因为有api版本管理的需求,重写了WebMvcConfigurationSupport类的 ...
- 为什么重写equals必须重写hoshCode的基础分析
为什么重写equals必须重写hoshCode的基础分析 1.我们先来了解下原生的equals和hashCode代码 原生equals:它判断的是两个对象是否相等 原生hashCode值:它是根据内存 ...
- 微信小程序初级教程
小程序代码构成 JSON 配置 WXML 模版 WXSS 样式 JS 逻辑交互 JSON 配置 在小程序中,JSON扮演的静态配置的角色. 小程序配置 app.json { "pages&q ...
- V2er - Best client for V2EX
V2er - Best client for V2EX 可能是体验最好的掌上 V2EX 客户端,专为 iOS 打造并在 Github 开源. 关于 V2EX,V2EX 是创意工作者们的社区.这里目前汇 ...
- Beetlex服务框架之Webapi版本访问控制
在应用服务中API更新是很普遍的事情,为了服务良好地运作很多时候需要新旧版本同时兼容:为了应对这一系列的需求FastHttpApi在新版中强化了Url重写机制来支持API访问版本控制,由原来固定的重写 ...
- Python 的多线程是鸡肋?
"唉,还没毕业就受到甲方的支配,等以后进了公司可咋整啊."小白嘴里这么吐槽,但心理上还是不敢怠慢,只能恋恋不舍地关掉眼前的游戏,打开了 Python 代码思考了起来. " ...
- Java基础(三十一)JDBC(1)常用类和接口
1.Driver接口 每种数据库的驱动程序都应该提供一个实现java.sql.Driver接口的类.在加载某一驱动程序的Driver类时,它应该创建自己的实例并向java.sql.DriverMana ...
- 存储路径与文件目录操作ZT
转自:https://www.cnblogs.com/zrr-notes/p/5953445.html (一)基本存储位置 我们的app在手机中存放的路径是:/var/mobile/Applicati ...
- 四元数(Quaternion)
从应用角度说一下unity Quaternion,Quaternion是四元数,百度相关资料可能找到的都是一些大牛给你搞个矩阵云云,给你讲解四元数.在此只是从应用角度讲一讲.最简单理解四元数对应一个向 ...
- nginx高可用集群
1.配置: (1)需要两台nginx服务器 (2)需要keepalived (3)需要虚拟ip 2.配置高可用的准备工作 (1)需要两台服务器192.168.180.113和192.168.180.1 ...