LCIS

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
Alex has two sequences a1,a2,...,an and b1,b2,...,bm. He wants find a longest common subsequence that consists of consecutive values in increasing order.
 
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains two integers n and m (1≤n,m≤100000) -- the length of two sequences. The second line contains n integers: a1,a2,...,an (1≤ai≤106). The third line contains n integers: b1,b2,...,bm (1≤bi≤106).

There are at most 1000 test cases and the sum of n and m does not exceed 2×106.

 
Output
For each test case, output the length of longest common subsequence that consists of consecutive values in increasing order.
 
Sample Input
3
3 3
1 2 3
3 2 1
10 5
1 23 2 32 4 3 4 5 6 1
1 2 3 4 5
1 1
2
1
 
Sample Output
1
5
0
 
Source
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=1e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int n,m;
int a[N],b[N];
int dpn[M],dpm[M];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int ans=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
dpn[a[i]]=max(dpn[a[i]],dpn[a[i]-]+);
}
for(int i=;i<=m;i++)
{
scanf("%d",&b[i]);
dpm[b[i]]=max(dpm[b[i]],dpm[b[i]-]+);
ans=max(ans,min(dpm[b[i]],dpn[b[i]]));
}
for(int i=;i<=n;i++)
dpn[a[i]]=;
for(int i=;i<=m;i++)
dpm[b[i]]=;
printf("%d\n",ans);
}
}

hdu 5904 LCIS dp的更多相关文章

  1. HDU 5904 - LCIS (BestCoder Round #87)

    HDU 5904 - LCIS [ DP ]    BestCoder Round #87 题意: 给定两个序列,求它们的最长公共递增子序列的长度, 并且这个子序列的值是连续的 分析: 状态转移方程式 ...

  2. HDU 5904 LCIS (最长公共上升序列)

    传送门 Description Alex has two sequences a1,a2,...,an and b1,b2,...,bm. He wants find a longest common ...

  3. HDU 5904 LCIS

    $dp$. 这题的突破口在于要求数字是连续的. 可以分别记录两个串以某个数字为结尾的最长上升长度,然后枚举一下以哪个数字为结尾就可以得到答案了. 因为$case$有点多,不能每次$memset$,额外 ...

  4. hdu 4123 树形DP+RMQ

    http://acm.hdu.edu.cn/showproblem.php? pid=4123 Problem Description Bob wants to hold a race to enco ...

  5. hdu 4507 数位dp(求和,求平方和)

    http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...

  6. hdu 3709 数字dp(小思)

    http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...

  7. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. hdu 4283 区间dp

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化

    HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...

随机推荐

  1. Axis-Parallel Rectangle

    D - Axis-Parallel Rectangle Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stat ...

  2. 将DataTable转换成Json格式

    方法一: 将DataTable数据拼接成json字符串,方法如下: ///<summary> /// dataTable转换成Json格式 ///</summary> ///& ...

  3. C# Static修饰符的作用

    MSDN上的定义 Use the static modifier to declare a static member, which belongs to the type itself rather ...

  4. Magic Cast Method in Java Magic Trick In Java

    https://www.atlassian.com/blog/archives/magic_trick_in_java https://www.gamlor.info/wordpress/2010/1 ...

  5. js对多行字符串的处理

    f = [] g = str(f) h = ''.join(f) dic_ = () gd = str(dic_) hd = ''.join(dic_) 0 老板1 北京2 上海3 天津4 重庆5 河 ...

  6. QSystemSemaphore 系统级信号量

    在之前的一篇文章中,我们讲过了QSemaphore类,其可以用于同步多线程.而今天要讲到的这个类,根据名字就可以猜测到,其可以在整个系统中使用,即它既可以用于多线程,也可以用于多线程.当然,这也意味着 ...

  7. hive bin下的进入beeline 命令行和hive有什么不同?

    Hive 0.11中引入的HiveServer2有一个自己的CLI叫Beeline. HiveCLI现在已经过时,与Beeline相比,其缺少多用户.安全和其他与HiveServer2兼容的特性. 从 ...

  8. kubernetes 1.7.2 安装 记录过程

    系统信息 cat /etc/redhat-release CentOS Linux release (Core) 环境信息 IP地址 主机名称 10.10.6.11 master 10.10.6.12 ...

  9. Mac 安装Minikube

    环境信息: guoguo-MacBook-Pro-3:~ guoguo$ docker versionClient: Version:    17.12.0-ce API version:    1. ...

  10. 003-Spring 中的StreamUtils

    一.概述 StreamUtils是spring中用于处理流的类,是java.io包中inputStream和outputStream,不是java8中Steam.使用时仅依赖spring-core 二 ...