HDU 1087 最长不下降子序列 LIS DP
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.
InputInput 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.
OutputFor 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 用最朴素的LIS解决办法就可以ac。
dp[i] = max(dp[i],dp[j]+arr[i])
然后记录答案 ans = max(ans,dp[i]);
输出ans就是答案了。
#include <bits/stdc++.h>
using namespace std; const int M = 1000+9;
int arr[M],dp[M]; int main()
{
int n;
while(scanf("%d",&n) != EOF && n)
{
memset(dp,0,sizeof(dp));
int ans = -99999;
for(int i = 0; i < n; i++)
scanf("%d",&arr[i]); for(int i = 0; i < n; i++)
{
dp[i] = arr[i];
for(int j = 0; j < i; j++)
{
if(arr[i] > arr[j])
dp[i] = max(dp[j]+arr[i],dp[i]);
}
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
}
return 0;
}
HDU 1087 最长不下降子序列 LIS DP的更多相关文章
- SPOJ 3943 - Nested Dolls 最长不下降子序列LIS(二分写法)
现在n(<=20000)个俄罗斯套娃,每个都有宽度wi和高度hi(均小于10000),要求w1<w2并且h1<h2的时候才可以合并,问最少能剩几个. [LIS]乍一看跟[这题]类似, ...
- luogu2766 最长不下降子序列问题 DP 网络流
题目大意:给定正整数序列x1,...,xn .(1)计算其最长不下降子序列的长度s.(不一定是否连续)(2)计算从给定的序列中最多可取出多少个长度为s的不下降子序列.(序列内每一个元素不可重复)(3) ...
- 最长不下降子序列//序列dp
最长不下降子序列 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 求最长不下降子序列的长度 输入格式 第一行为n,表示n个数第二行n个数 输出格式 最长不下降 ...
- Codeforces Round #323 (Div. 2) Once Again... CodeForces - 582B 最长非下降子序列【dp】(不明白)
B. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- SPOJ 4053 - Card Sorting 最长不下降子序列
我们的男主现在手中有n*c张牌,其中有c(<=4)种颜色,每种颜色有n(<=100)张,现在他要排序,首先把相同的颜色的牌放在一起,颜色相同的按照序号从小到大排序.现在他想要让牌的移动次数 ...
- HDU 6357.Hills And Valleys-字符串非严格递增子序列(LIS最长非下降子序列)+动态规划(区间翻转l,r找最长非递减子序列),好题哇 (2018 Multi-University Training Contest 5 1008)
6357. Hills And Valleys 自己感觉这是个好题,应该是经典题目,所以半路选手补了这道字符串的动态规划题目. 题意就是给你一个串,翻转任意区间一次,求最长的非下降子序列. 一看题面写 ...
- 最长不下降子序列(LIS)
最长上升子序列.最长不下降子序列,解法差不多,就一点等于不等于的差别,我这里说最长不下降子序列的. 有两种解法. 一种是DP,很容易想到,就这样: REP(i,n) { f[i]=; FOR(j,,i ...
- hdu 4604 Deque(最长不下降子序列)
从后向前对已搜点做两遍LIS(最长不下降子序列),分别求出已搜点的最长递增.递减子序列长度.这样一直搜到第一个点,就得到了整个序列的最长递增.递减子序列的长度,即最长递减子序列在前,最长递增子序列在后 ...
- [Swust OJ 585]--倒金字塔(LIS最长不下降子序列)
题目链接:http://acm.swust.edu.cn/problem/585/ Time limit(ms): 3000 Memory limit(kb): 65535 SWUST国的一支科学 ...
随机推荐
- [daily][dpdk] 内核模块(网卡驱动)无法卸载
由于程序的异常退出, 内核的引用计数没有被清除(我猜的). 所以驱动不能被卸载掉, 强制也不行. 如下: [root@localhost ~]# insmod /opt/scorpion/KingKo ...
- python3实现字符串的全排列的方法(无重复字符)
https://www.jb51.net/article/143357.htm 抛出问题 求任意一个字符串的全排列组合,例如a='123',输出 123,132,213,231,312,321.(暂时 ...
- 《mongoDB》基本操作-创建/更新/删除文档
一:基本操作 - db; 当前选择的集合(等于数据库名) > db demo - use db_name; 选择你要操作的集合 > use demo switched to db dem ...
- scala-数组/列表
import scala.collection.mutable.ArrayBuffer var ary=Array(1,2,3) println(ary.mkString) println(ary(1 ...
- nginx 、springMvc(非分布式)相应的限流、消峰
互联网服务赖以生存的根本是流量, 产品和运营会经常通过各种方式来为应用倒流,比如淘宝的双十一等,如何让系统在处理高并发的同时还是保证自身系统的稳定, 通常在最短时间内提高并发的做法就是加机器, 但是如 ...
- gitlab访问用户安装的postgresql数据库
1.先将gitlab默认安装的postgresql的数据库中的数据,导入到用户安装的postgresql数据 用Navicat迁移数据.函数不用迁移. 2.配置gitlab对postgresql数据库 ...
- 用laravel dingo/api创建产品api
沿着上一篇来讲,我们来创建一个简单的item产品api,也是用到laravel dingo/api来实现,对dingo/api不熟的朋友可以翻看前面的文章.好,我们随着ytkah一起来创建产品api ...
- 对比库表结构,生成SQL
网上找了一圈对比库的工具,能手工生成差别的SQL的工具没有,改造了一下网上的sql 1, 获取字段名的类型 create FUNCTION [dbo].[getColType](@tab varcha ...
- 运维自动化ansible基础
云计算三种服务架构 IAAS: 不提供OS 只购买硬件(网络,存储,计算) PAAS: 提供硬件和OS和开发和运行环境 只需要开发应用软件 SAAS: 提供 硬件 os 软件 相当于直接购买软 ...
- 接口,定义接口的关键字是 interface 实现接口关键字是 implements
当抽象类中的方法都是抽象的时候,这时可以将该抽象类用另一种形式定义和表示,就是接口interface特点:对于接口中常见的成员:而且这些成员都有固定的修饰符,不写就默认存在1:全局常量 : 都是 p ...