CH5101 LICS//hdu5904 LICS
恭喜我已经正式沦为pj组选手QwQ
一、CH上的:裸题,求LICS。n<=3000
经典普及组dp题,题解烂大街了。所以对于这题,只讲细节:
$1.A_i=B_j时的转移(或者说继承)f[i][j]=f[i-1][j]可有可无。$
$可以想到两个末尾相等时由A的前i-1个,B不以B_j为结尾的状态转移$
$LICS长最多少掉一个。$
$那么这样取到的前面max(f[i-1][k])至少会是f[i-1][j]-1,再加上最后相等的1个$
$一定不会比f[i-1][j]差。所以这句有无皆可。(当然我自己写是不会想这么多的)$
$2.前缀max优化,这个不必说了。$ 不方便优化时看能否调换枚举顺序,调换后可不可以优化枚举。
我好菜啊啊啊 啊啊啊啊啊 啊啊啊啊
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define ddbg(x,y) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
using namespace std;
typedef long long ll;
template<typename T>inline char MIN(T&A,T B){return A>B?A=B,:;}
template<typename T>inline char MAX(T&A,T B){return A<B?A=B,:;}
template<typename T>inline T _min(T A,T B){return A<B?A:B;}
template<typename T>inline T _max(T A,T B){return A>B?A:B;}
template<typename T>inline T read(T&x){
x=;int f=;char c;while(!isdigit(c=getchar()))if(c=='-')f=;
while(isdigit(c))x=x*+(c&),c=getchar();return f?x=-x:x;
}
const int N=+;
int f[N][N],a[N],b[N],m,n,maxv,ans; int main(){//freopen("test.in","r",stdin);//freopen("test.out","w",stdout);
m=read(n);
for(register int i=;i<=n;++i)scanf("%d",&a[i]);for(register int i=;i<=n;++i)scanf("%d",&b[i]);
for(register int i=;i<=n;++i){
maxv=;
for(register int j=;j<=m;++j){
if(a[i]==b[j])f[i][j]=maxv+;
else f[i][j]=f[i-][j],b[j]<a[i]?MAX(maxv,f[i-][j]):;
MAX(ans,f[i][j]);
}
}
return printf("%d\n",ans),;
}
二、hdu上的:跪于英语不好。。
Original:He wants find a longest common subsequence that consists of consecutive values in increasing order.
也就是LICS要求是连续上升的(也就是公差是1)
那这不就简单了么。
两数组各做一遍dp,求以这个数结尾的最大连续长度。最后比对一下。
没了。code不放了。
CH5101 LICS//hdu5904 LICS的更多相关文章
- lintcode 最长上升连续子序列 II(二维最长上升连续序列)
题目链接:http://www.lintcode.com/zh-cn/problem/longest-increasing-continuous-subsequence-ii/ 最长上升连续子序列 I ...
- 最长公共子序列模板(LCS)和LICS模板
递归式: 实例图解: 代码: #include<stdio.h> #include<string.h> ; int dp[N][N],f[N][N]; char a[N],b[ ...
- Longest Increasing Common Subsequence (LICS)
最长上升公共子序列(Longest Increasing Common Subsequence,LICS)也是经典DP问题,是LCS与LIS的混合. Problem 求数列 a[1..n], b[1. ...
- 最长公共上升子序列(LICS) 模板
void LICS() { ;i<=n;i++) { ; ;j<=n;j++) { if (a[i]==b[j]) f[i][j]=ma+; ][j]; ][j]>ma) ma=f[ ...
- HDU4512:吉哥系列故事——完美队形I(LICS)
Problem Description 吉哥这几天对队形比较感兴趣. 有一天,有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一 ...
- HDU1423:Greatest Common Increasing Subsequence(LICS)
Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the lengt ...
- 最长递增子序列(lis)最长公共子序列(lcs) 最长公共上升子序列(lics)
lis: 复杂度nlgn #include<iostream> #include<cstdio> using namespace std; ],lis[],res=; int ...
- LICS O(n*m)+前驱路径
LICS:最长公共上升子序列: 一般令f[i][j]表示a串前i位,b串以j结尾的LICS长度.于是,答案为:max(1~m)(f[n][i]); 朴素做法:O(n^3) 相等时,从1~j-1枚举最大 ...
- POJ2127 LICS模板
题目:http://poj.org/problem?id=2127 十分费劲地终于记录好了路径……用一个前驱. 这是 n^2 的LICS方法.其实就是 n ^ 2 log n 把“找之前的d [ j ...
随机推荐
- C# 创建桌面快捷方式 用法
项目--->添加引用 找到 头部 using IWshRuntimeLibrary; 核心代码 string desktoppath = System.Environment.GetFold ...
- 338.比特位计数( Counting Bits)leetcode
附上:题目地址:https://leetcode-cn.com/problems/counting-bits/submissions/ 1:题目: 给定一个非负整数 num.对于 0 ≤ i ≤ nu ...
- ubuntu 编译安装 svn
1,简单的安装svn (1) sudo apt-get install subversion 但是此种方式,可能不能安装到当前最新的svn.如当前最新的版本是svn 1.8.9 ,但是 通过此种安装 ...
- VS显示代码行号
工具>文本编辑器>常规 如图勾选行号选项,点击确定即可显示行号. 如果没有行号的选项,则需先勾选下图中左下角的‘’显示所有设置选‘’‘项.
- js继承的方式及其优缺点
js继承方法 前因:ECMAScript不支持接口继承,只支持实现继承 一.原型链 概念:每个构造函数都有一个原型对象,原型对象都包含一个指向构造函数的指针,而实例都包含一个指向原型对象的内部指针,让 ...
- 转-性能优化中CPU、内存、磁盘IO、网络性能的依赖
转自:https://www.cnblogs.com/Javame/p/3665565.html 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估. ...
- CentOS7下MySQL服务启动失败原因及解决方法
在重启阿里的CentOS7服务器后,重启MySQL 出现错误 Starting mysqld (via systemctl): Job for mysqld.service failed becaus ...
- Python_3day
循环 循环是一种控制语句块重复执行的结构 while 适用于广度遍历 for 开发中经常使用 while 循环 当一个条件保持真的时候while循环重复执行语句 while 循环一定要有结束条件, ...
- vscode中eslint插件的配置-prettier
用vue-cli构建vue项目,会有个eslint代码检测的安装 可vscode自带代码格式化是prettier格式(右键有格式化文件或alt+shift+f) 这时候要在vscode上装一个esli ...
- 编译LAMP部署动态网站环境
LAMP动态网站部署架构是由一套 Linux+Apache+MySQL+PHP 组成的动态网站系统解决方案. 以下配置环境为:Linux=RHEL7 --> Apache=2.4.33 --&g ...