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. 【BZOJ5047】空间传送装置 最短路

    [BZOJ5047]空间传送装置 Description 太空中一共有n座星球,它们之间可以通过空间传送装置进行转移.空间传送装置分为m种,第i种装置可以用4个参数a_i,b_i,c_i,d_i来描述 ...

  2. 爬虫入门【8】Python连接MongoDB的用法简介

    MongoDB的连接和数据存取 MongoDB是一种跨平台,面向文档的NoSQL数据库,提供高性能,高可用性并且易于扩展. 包含数据库,集合,文档等几个重要概念. 我们在这里不介绍MongoDB的特点 ...

  3. Olya and Energy Drinks(bfs)

    D. Olya and Energy Drinks time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  4. UVA Dividing coins

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  5. 创建String字符串的方式与区别

    Java中创建一个字符串的方式有很多种,常见如: String s = new String("riqi"); String s = "riqi"; 但两者有什 ...

  6. CAS单点登录------302个没完没了

    我的配置如上 背景:Shiro + Cas 进行的单点登录配置! 其实这个问题很扯淡!看代码! 我本在shiro里面配置的Sucessurl !嘿嘿!我哭了!屌用没有! 我一脸懵逼大写的WHY??? ...

  7. iOS 多线程之 GCD 的基本使用

    什么是GCD 全称Grand Central Dispatch 中暑调度器 纯C语言 提供了很多强大的函数 GCD 的优势 GCD是苹果公司为多核的并行运算提出的解决方案 GCD会自动利用更多的CPU ...

  8. CentOS6.9添加环境变量

    方法一:直接运行命令export PATH=$PATH:~/.composer/vendor/bin 使用这种方法,只会对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效,只是临时 ...

  9. 云原生应用开发12-Factors

    英文地址:https://12factor.net/ 中文地址:https://12factor.net/zh_cn/ 文章内容 简介 如今,软件通常会作为一种服务来交付,它们被称为网络应用程序,或软 ...

  10. 第K层的结点数

    int GetNodeNumKthLevel(BiTNode * pRoot, int k) { if(pRoot == NULL || k < 1) return 0; if(k == 1) ...