最长上升子序列(LIS) dp学习~3
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1087
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 30228 Accepted Submission(s): 13530

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
10
3
题意:求递增段最大和
题解:类似于最长上升子序列求法,dp[i]表示,到i结尾的最大值,这道题要注意的问题是要设置一个max值保存每个点dp的最大值作为最后结果
if(mp[j]<mp[i])
dp[i] = max(dp[i],dp[j]+mp[i]);
代码;
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = ;
int mp[N];
int dp[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
if(n==) return ;
for(int i = ; i < n; i++)
{
scanf("%d",&mp[i]);
dp[i] = mp[i];
}
int sum = ;
for(int i = ; i < n; i++)
{
for(int j = ; j < i; j++)
{
if(mp[j]<mp[i])
dp[i] = max(dp[i],dp[j]+mp[i]);
//else dp[i] = max(dp[i],dp[j]);这么写是错误的因为遍历后面的点的时候仍会用到这个点的值。
}
sum = max(sum,dp[i]);
}
printf("%d\n",sum);
}
return ;
}
最长上升子序列(LIS) dp学习~3的更多相关文章
- 动态规划(DP),最长递增子序列(LIS)
题目链接:http://poj.org/problem?id=2533 解题报告: 状态转移方程: dp[i]表示以a[i]为结尾的LIS长度 状态转移方程: dp[0]=1; dp[i]=max(d ...
- 1. 线性DP 300. 最长上升子序列 (LIS)
最经典单串: 300. 最长上升子序列 (LIS) https://leetcode-cn.com/problems/longest-increasing-subsequence/submission ...
- 最长上升子序列LIS(51nod1134)
1134 最长递增子序列 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递 ...
- 最长上升子序列(LIS)与最长公共子序列(LCS)
1.LIS : 给定一个序列,求它的最长上升子序列(n<=2000) 第一种 O(n^2): dp[i] 为以i为开头的最长上升子序列长度 code1: #include<cstdio&g ...
- 【部分转载】:【lower_bound、upperbound讲解、二分查找、最长上升子序列(LIS)、最长下降子序列模版】
二分 lower_bound lower_bound()在一个区间内进行二分查找,返回第一个大于等于目标值的位置(地址) upper_bound upper_bound()与lower_bound() ...
- 最长回文子序列LCS,最长递增子序列LIS及相互联系
最长公共子序列LCS Lintcode 77. 最长公共子序列 LCS问题是求两个字符串的最长公共子序列 \[ dp[i][j] = \left\{\begin{matrix} & max(d ...
- 2.16 最长递增子序列 LIS
[本文链接] http://www.cnblogs.com/hellogiser/p/dp-of-LIS.html [分析] 思路一:设序列为A,对序列进行排序后得到B,那么A的最长递增子序列LIS就 ...
- 题解 最长上升子序列 LIS
最长上升子序列 LIS Description 给出一个 1 ∼ n (n ≤ 10^5) 的排列 P 求其最长上升子序列长度 Input 第一行一个正整数n,表示序列中整数个数: 第二行是空格隔开的 ...
- POJ - 1631 Bridging signals(最长上升子序列---LIS)
题意:左右各n个端口,已知n组线路,要求切除最少的线路,使剩下的线路各不相交,按照左端口递增的顺序输入. 分析: 1.设左端口为l,右端口为r,因为左端口递增输入,l[i] < l[j](i & ...
- 一个数组求其最长递增子序列(LIS)
一个数组求其最长递增子序列(LIS) 例如数组{3, 1, 4, 2, 3, 9, 4, 6}的LIS是{1, 2, 3, 4, 6},长度为5,假设数组长度为N,求数组的LIS的长度, 需要一个额外 ...
随机推荐
- 关于《ASP.NET MVC企业级实战》
大家好,我的书<ASP.NET MVC企业级实战>已经出版啦,感谢大家过去的关注与支持!前言部分,出版的时候漏了部分内容,我这里将其贴出来. 本书提供源码和教学PPT课件!(源码在书中第3 ...
- ES6常用语法
ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准.因为当前版本的ES6是在2015年发布的,所以又称ECMAScript 2015. 也就是说,ES6就是ES2015. ...
- Arcade初探[0] 目录与导航
2017年6月,ESRI开发者页面出现了一个新玩意儿:Arcade. 连接:点我 这是什么东西呢?有什么用呢? 1. 是什么 Arcade一种表达语言,可以在ArcGIS平台上使用.不管是编写简单的脚 ...
- Windows as a Service(1)—— Windows 10服务分支
前言 作为公司的IT管理员,管理全公司Windows 10操作系统的更新一直是工作中的头疼之处.微软提供了很多方法来帮助我们管理公司的Windows 10更新,比如Windows Server Upd ...
- 用原生实现点击删除点击的li
简单的实现方式 <!DOCTYPE html> <html> <head> <title></title> <meta charset ...
- vue 回到顶部的小问题
今天在用vue项目中,实现回到顶部功能的时候,我写了一个backTop组件,接下来需要通过监听window.scroll事件来控制这个组件显示隐藏 因为可能会有其他的组件会用到这样的逻辑,所以将此功能 ...
- java.util.HashSet
Operations Time Complexity Notes add, remove, contains, size O(1) assuming the hash functions has di ...
- 从源码(编译)安装golang
从源码安装golang 通常情况下,安装go只需要在官网(https://golang.org/dl/)下载适合系统的二进制发布包,按照安装说明进行安装即可. 对于Linux, Mac OS X和Fr ...
- WebDriver API 大全
访问某网页地址:driver.get(url) 或 driver.navigate().to(url) 访问上一个访问的网页(模拟单击浏览器的后退按钮)driver.navigate().back ...
- ValueError: 'format' in __slots__ conflicts with class variable
Complete output from command python setup.py egg_info: Traceback (most recent call last): File " ...