$dp$。

这题的突破口在于要求数字是连续的。

可以分别记录两个串以某个数字为结尾的最长上升长度,然后枚举一下以哪个数字为结尾就可以得到答案了。

因为$case$有点多,不能每次$memset$,额外开一个数组记录一下这组$case$中数字有没有出现过。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
int dp[*maxn],f[*maxn],n,m;
int s1[*maxn],s2[*maxn]; int main()
{
int T; scanf("%d",&T);
for(int cas=;cas<=T;cas++)
{
dp[]=; f[]=; s1[]=cas; s2[]=cas;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
int x; scanf("%d",&x);
if(s1[x]<cas) s1[x]=cas, dp[x]=;
if(s1[x-]<cas) dp[x-]=;
dp[x]=max(dp[x],dp[x-]+);
}
int ans=;
for(int i=;i<=m;i++)
{
int x; scanf("%d",&x);
if(s2[x]<cas) s2[x]=cas, f[x]=;
if(s2[x-]<cas) f[x-]=;
f[x]=max(f[x],f[x-]+);
if(s1[x]<cas) dp[x]=;
int pp=min(f[x],dp[x]);
ans=max(ans,pp);
}
printf("%d\n",ans);
}
return ;
}

HDU 5904 LCIS的更多相关文章

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

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

  2. hdu 5904 LCIS dp

    LCIS Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Des ...

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

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

  4. 【14.06%】【hdu 5904】LCIS

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

  5. hdu 3308 LCIS(线段树区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3308 LCIS Time Limit: 6000/2000 MS (Java/Others)     ...

  6. HDU 3308 LCIS(线段树)

    Problem Description Given n integers.You have two operations:U A B: replace the Ath number by B. (in ...

  7. hdu 3308 LCIS 线段树

    昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...

  8. HDU 3308 LCIS (线段树区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...

  9. 线段树(区间维护):HDU 3308 LCIS

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

随机推荐

  1. ASP.NET所谓前台调用后台、后台调用前台想到HTTP——实践篇

    由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——实践篇 在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——理论篇中描述了一下ASP.NET新手的三个问题及相关的HTTP协议 ...

  2. SQLSERVER用无中生有的思想来替代游标

    SQLSERVER用无中生有的思想来替代游标 SQLSERVER用无中生有的思想来替代游标 昨天在MSDN论坛看到一个帖子,帖子中LZ需要根据某列的值把其他列的值插入到额外列 帖子地址:http:// ...

  3. 解决MSSQL 2008不能用IP登录的问题

        解决MSSQL 2008不能用IP登录的问题   前提准备:mssql 2008已安装好了一个实例(我按默认情况下安装的实例是:SQLEXPRESS),并安装了SQL Server Manag ...

  4. 解决TXT乱码问题

    初装Ubuntu,打开windows保存的txt文件很可能会遇到各种乱码问题. 下面是wiki ubuntu里的解决办法: Gedit中文乱码 缺省配置下,用 Ubuntu 的文本编辑器(gedit) ...

  5. 熬之滴水成石:Spring--精简的J2EE(7)

                                              49--持久性 关于持久性在最早的Delphi单元中,就曾介绍过.持久性是数据库中读取,保存,或删除数据的过程.毫无 ...

  6. Android 检测是否连接蓝牙耳机

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  7. SVN插件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  8. bzoj 1430: 小猴打架 -- prufer编码

    1430: 小猴打架 Time Limit: 5 Sec  Memory Limit: 162 MB Description 一开始森林里面有N只互不相识的小猴子,它们经常打架,但打架的双方都必须不是 ...

  9. Flexible 弹性盒子模型之CSS align-items 属性

    实例 居中对齐弹性盒的各项 <div> 元素: div { display: flex; align-items:center; } 复制 效果预览 浏览器支持 表格中的数字表示支持该属性 ...

  10. 运行Google 官方zxing二维码扫描器

    首先,要去下载Zxing的源码,由于Zxing 的服务内容比较广,我们先把所有的源码都下载下来,使用的时候根据需要加载. 或者从开源中国下载https://www.oschina.net/questi ...