恭喜我已经正式沦为pj组选手QwQ

标题两个题其实不一样的。这是ch   这是hdu


一、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的更多相关文章

  1. lintcode 最长上升连续子序列 II(二维最长上升连续序列)

    题目链接:http://www.lintcode.com/zh-cn/problem/longest-increasing-continuous-subsequence-ii/ 最长上升连续子序列 I ...

  2. 最长公共子序列模板(LCS)和LICS模板

    递归式: 实例图解: 代码: #include<stdio.h> #include<string.h> ; int dp[N][N],f[N][N]; char a[N],b[ ...

  3. Longest Increasing Common Subsequence (LICS)

    最长上升公共子序列(Longest Increasing Common Subsequence,LICS)也是经典DP问题,是LCS与LIS的混合. Problem 求数列 a[1..n], b[1. ...

  4. 最长公共上升子序列(LICS) 模板

    void LICS() { ;i<=n;i++) { ; ;j<=n;j++) { if (a[i]==b[j]) f[i][j]=ma+; ][j]; ][j]>ma) ma=f[ ...

  5. HDU4512:吉哥系列故事——完美队形I(LICS)

    Problem Description 吉哥这几天对队形比较感兴趣. 有一天,有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一 ...

  6. 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 ...

  7. 最长递增子序列(lis)最长公共子序列(lcs) 最长公共上升子序列(lics)

    lis: 复杂度nlgn #include<iostream> #include<cstdio> using namespace std; ],lis[],res=; int ...

  8. 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枚举最大 ...

  9. POJ2127 LICS模板

    题目:http://poj.org/problem?id=2127 十分费劲地终于记录好了路径……用一个前驱. 这是 n^2 的LICS方法.其实就是 n ^ 2 log n 把“找之前的d [ j ...

随机推荐

  1. 字符串转 Boolean 的正确方式

    String s1 = "false"; String s2 = "true"; String s3 = "fAlSe"; String s ...

  2. kafka服务器批量copy文件脚本

    #!/bin/bashif [[ $# -lt 1 ]] ; then echo no params ; exit ; fiparams=$@for (( i=1 ; i <= 3 ; i = ...

  3. PTA(Basic Level)1036.跟奥巴马一起编程

    美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014 年底,为庆祝"计算机科学教育周"正式启动,奥巴马编写了很简单的计算机 ...

  4. Ubuntu - Ubuntu应用记录(2)

    1.安装Ubuntu16.04的一种分区分案(240G固态硬盘小例) 1.创建boot分区(引导分区)-> 512M ->逻辑分区->空间起始位置->Ext4日志文件系统-&g ...

  5. MSSQL读取某视图中的字段类型及相关属性

    SELECT 新字段类型 = '',表名 = case when a.colorder=1 then d.name else '' end,表说明 = case when a.colorder=1 t ...

  6. ABC136E Max GCD

    Thinking about different ways of thinking. --- LzyRapx 题目 思路比较容易想到. Observations: 每次操作过后和不变. 枚举和的因子 ...

  7. 测试必知150个常用Linux命令,已为各位筛选整理

    ●线上查询及帮助命令(1 个) help   如:mkdir --help   ●文件和目录操作命令(12 个)    ls tree pwd mkdir rmdir cd touch cp mv r ...

  8. 最长上升子序列(Longest increasing subsequence)

    问题描述        对于一串数A={a1a2a3…an},它的子序列为S={s1s2s3…sn},满足{s1<s2<s3<…<sm}.求A的最长子序列的长度. 动态规划法 ...

  9. 在Powershell中使用Group-Object和-GroupBy

    使用Group-Object(group)按组统计 PS C:\> Get-Command -Module Microsoft.PowerShell.LocalAccounts | group ...

  10. Nginx编译参数详解

    Nginx编译参数 1.当我们安装好nginx后,输入命令  nginx -V 可以看到nginx的编译参数信息,例如 如下图 2. 编译参数如下图 # Nginx安装目的目录或路径 --prefix ...