动态规划:HDU1087-Super Jumping! Jumping! Jumping!(最大上升子序列和)
Super Jumping! Jumping! Jumping!
Total Submission(s): 24374 Accepted Submission(s): 10740
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.
4 1 2 3 4
4 3 3 2 1
0
4
10
3
解题心得:
1、就是求一个最长上升子序列的和,子序列不一定要相邻,这个动态规划可以先看前三项,dp[1] = num[1],这是num[2]如果大于num[1],dp[2] = dp[1] + num[2],否则dp[2] = num[2],在看第三个num[3],如果num[3]大于num[2]那么dp[3]
= dp[2] + num[3],如果num[3]大于num[1],dp[3] = dp[1] + num[3],如果num[3]不大于num[2]同时也不大于num[1],dp[3] = num[3]。说了这么多其实就是一个意思,用之前的每一个数和当前的数比较,比当前数小的就加上dp【之前数】,不然就等于当前数。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
long long num[maxn];
long long dp[maxn];
void pre_num(int n)
{
memset(dp,0,sizeof(dp));
num[0] = 0;
for(int i=1;i<=n;i++)
scanf("%d",&num[i]);
} void get_ans(int n)
{
long long Max = -1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=i;j++)
{
if(num[j] < num[i])
dp[i] = max(dp[i],dp[j]+num[i]);//之前数比当前数小,就加上当前数到之前数的和上面
}
dp[i] = max(dp[i],num[i]);//之前数都不比当前数小的情况下直接就是当前数
if(dp[i] > Max)//记录最大的那个和
Max = dp[i];
} printf("%lld\n",Max);
}
int main()
{
int n;
while(scanf("%d",&n) && n)
{
pre_num(n);
get_ans(n);
}
}
动态规划:HDU1087-Super Jumping! Jumping! Jumping!(最大上升子序列和)的更多相关文章
- HDU1087 - Super Jumping! Jumping! Jumping!【动态规划】
zh成功的在他人的帮助下获得了与小姐姐约会的机会,同时也不用担心被非"川大"的女票发现了,可是如何选择和哪些小姐姐约会呢?zh希望自己可以循序渐进,同时希望挑战自己的极限,我们假定 ...
- 解题报告 HDU1087 Super Jumping! Jumping! Jumping!
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU1087:Super Jumping! Jumping! Jumping!(DP)
Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very ...
- HDU1087 Super Jumping! Jumping! Jumping! 最大连续递增子段
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- kuangbin专题十二 HDU1087 Super Jumping! Jumping! Jumping! (LIS)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU1087 Super Jumping! Jumping! Jumping! —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limi ...
- hdu1087 Super Jumping! Jumping! Jumping!---基础DP---递增子序列最大和
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 题目大意: 求递增子序列最大和 思路: 直接dp就可以求解,dp[i]表示以第i位结尾的递增子 ...
- HDU1087 Super Jumping! Jumping! Jumping!(LIS)
题目意思: http://acm.hdu.edu.cn/showproblem.php? pid=1087 此题的意思求最长上升子序列的和. 题目分析: 在求最长上升子序列的时候,不在保存最长的个数, ...
- HDu1087 Super Jumping! Jumping! Jumping!
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 分析:简单dp:dp[i] = max (dp[i], dp[j] + a[i]) 1 #inc ...
- HDU 1087 Super Jumping! Jumping! Jumping!(最长上升子序列,dp)
以下引用自:http://www.cnblogs.com/Lyush/archive/2011/08/31/2161314.html沐阳 该题可以算是一道经典的DP题了,题中数据是这样的.以 3 1 ...
随机推荐
- 最简实例演示asp.net5中用户认证和授权(4)
上篇: 最简实例演示asp.net5中用户认证和授权(3) 上面我们把自定义认证和授权的相关的最小基础类和要实现的接口都实现了,下面就是如何来进行认证和授权的配置. 首先我们要告诉系统,我们的用户和角 ...
- 《C#高效编程》读书笔记11-理解短小方法的优势
我们最好尽可能的编写最清晰的代码,将优化交给JIT编译器完成.一个常见的错误优化是,将大量逻辑放在一个函数中,以期减少额外的方法调用开销.这种将函数逻辑直接写在循环内部的常见优化做法却会降低.NET应 ...
- c#写word文档基础操作(自己控制样式)
下面一个函数,建立一个Word 文档,添加页眉.页脚,在内容中两个不同字体的Hello!!! 来自 <http://bbs.csdn.net/topics/340041961> pub ...
- hibernate课程 初探单表映射3-3 对象类型
本节简介: 1 简介对象类型(重点是音视频blob类型) 2 demo(对图片的写入数据库与读取) 1 简介对象类型 映射类型 java类型 标准sql类型 mysql类型 oracle类型 bina ...
- hibernate课程 初探单表映射2-1 hibernate进阶 本章简介
本章简介,主要讲5大块的内容 1 hibernate.cfg.xml的配置 2 session 的简介 3 transaction的简介 4 session的详解 5 对象关系映射常用配置
- python基础之循环语句
一.if条件语句: 语法: 1.if单分支(单重条件判断) if expression: expr_true_suite 注释:expession为真执行代码expr_true_suite if单分支 ...
- css3动画-加载中...
写几个简单的加载中动画吧. 像前面三种都是相当于几个不同的点轮流来播放同一动画:变大变小.css3里面有一个用于尺度变换的方法:scale(x,y):定义 2D 缩放转换,改变元素的宽度和高度. 第四 ...
- LeetCode Reverse Words in a String 将串中的字翻转
class Solution { public: void reverseWords(string &s) { string end="",tem="" ...
- NOIP2018赛前停课集训记(10.24~11.08)
前言 为了不久之后的\(NOIP2018\),我们的停课从今天(\(Oct\ 24th\))起正式开始了. 本来说要下周开始的,没想到竟提早了几天,真是一个惊喜.毕竟明天有语文考试.后天有科学考试,逃 ...
- geoNear查询 near查询的升级版
geoNear查询可以看作是near查询点进化版 geoNear查询使用runCommand命令进行使用,常用使用如下: db.runCommand({ geoNear:<collection& ...