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: ...
随机推荐
- spring boot 2.x文件路径映射问题汇总
当我们在运行可执行的java jar包的时候,我们肯定改变不了jar里面的内容,因此文件上传路径就成了我们必须考虑的一点问题,我们不能往直接这个jar包里面写文件,那么只能写在jar包外面,但是写到j ...
- HDU 3371 Connect the Cities(并查集+Kruskal)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=3371 思路: 这道题很明显是一道最小生成树的题目,有点意思的是,它事先已经让几个点联通了.正是因为它先 ...
- Docker卷
要解决的问题:在移除了现有容器或者添加了新容器时,之前容器的数据无法访问. 为避免上述问题,Docker提供了以下策略来持久化数据 tmpfs挂载 绑定挂载 卷 1.tmpfs挂载 2.绑定挂载 将D ...
- linux-查看服务器内存使用情况(free top)
free命令:显示系统使用和空闲的内存情况,包括物理内存.交互区内存(swap)和内核缓冲区内存. [root@ipha-dev71- workspace]# free # kb total used ...
- 详解Java Web项目启动执行顺序
一. web.xml加载过程(步骤): 启动web项目,容器(如Tomcat.Apache)会去读取它的配置文件web.xml 中的两个节点,context-param和listener. 紧接着,容 ...
- Redis 集群搭建(基于Linux)
一.基础环境 1.虚拟机 VMware 15.x 2.Linux系统,用的是Centos7的Linux系统 3.Redis数据库版本 5.0.3 二.Redis集群简介 1.背景 Redis在3.0版 ...
- 百万年薪python之路 -- python2和python3的区别
python2和python3的区别: python2获取的是整数 python3获取的是浮点数 print函数:(Python3中print为一个函数,必须用括号括起来:Python2中print为 ...
- Python 常见异常类型
python标准异常 异常名称 描述 BaseException 所有异常的基类Sy ...
- 利用span设置文字固定宽度
<input type="radio" name="dispMode" id="rdoManul" value="manul ...
- Codeforces Round #595 (Div. 3)B2 简单的dfs
原题 https://codeforces.com/contest/1249/problem/B2 这道题一开始给的数组相当于地图的路标,我们只需对每个没走过的点进行dfs即可 #include &l ...