LCIS
传送门
http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=726&pid=1003
分析:这道题依然是动态规划,实际上是经典问题的变形,因为要求值必须连续,所以我们应该采取一些特殊的手段。
我们设f[i]表示f[i]为第一个序列中以高度i为结尾的最长连续递增子序列,使用g[i] 表示第二个序列的所以每读入一个数
所以我们有f[i] = f[i-1] + 1;g[i]类似
然后我们考虑统计答案,易得,ans = max{min{f[i],g[i]}}
因为要求的是公共子序列,所以不能选择两个序列中长的那个,也就是说,我们一定有较短的序列出现在另一个序列中。
所以我们就可以统计答案了。
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=*x+ch-'',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = ;
const int maxnum = ;
int f[maxnum],g[maxnum];
int a[maxn],b[maxn];
int main(){
int T;read(T);
while(T--){
int n,m;read(n);read(m);
for(int i=;i<=n;++i){
read(a[i]);
f[a[i]] = f[a[i]-] + ;
}int ans = ;
for(int i=;i<=m;++i){
read(b[i]);
g[b[i]] = g[b[i]-] + ;
ans = cat_max(ans,cat_min(f[b[i]],g[b[i]]));
}printf("%d\n",ans);
for(int i=;i<=n;++i) f[a[i]] = ;
for(int i=;i<=m;++i) g[b[i]] = ;
}
getchar();getchar();
return ;
}
LCIS的更多相关文章
- BestCoder Round #87 1003 LCIS[序列DP]
LCIS Accepts: 109 Submissions: 775 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65 ...
- LCIS(最长公共上升子序列)Vijos1264神秘的咒语
描述 身为拜月教的高级间谍,你的任务总是逼迫你出生入死.比如这一次,拜月教主就派你跟踪赵灵儿一行,潜入试炼窟底. 据说试炼窟底藏着五行法术的最高法术:风神,雷神,雪妖,火神,山神的咒语.为了习得这些法 ...
- 最长公共上升子序列(LCIS)
最长公共上升子序列慕名而知是两个字符串a,b的最长公共递增序列,不一定非得是连续的.刚开始看到的时候想的是先用求最长公共子序列,然后再从其中找到最长递增子序列,可是仔细想一想觉得这样有点不妥,然后从网 ...
- hdu-5904 LCIS(水题)
题目链接: LCIS Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- LCIS HDOJ 4512 吉哥系列故事——完美队形I
题目传送门 题意:中文题面 分析:LCIS应用:设置b[]为a[]的反转,然后LCIS,若相等的是自己本身,则+1, 否则+2 代码: #include <cstdio> #include ...
- LCIS POJ 2172 Greatest Common Increasing Subsequence
题目传送门 题意:LCIS(Longest Common Increasing Subsequence) 最长公共上升子序列 分析:a[i] != b[j]: dp[i][j] = dp[i-1][j ...
- LIS+LCS+LCIS
PS:本篇博文均采用宏#define FOR(i, a, n) for(i = a; i <= n; ++i) LIS:最长上升子序列 废话不多说:http://baike.baidu.com/ ...
- HDU 4718 The LCIS on the Tree(树链剖分)
Problem Description For a sequence S1, S2, ... , SN, and a pair of integers (i, j), if 1 <= i < ...
- HDU 3308 LCIS(线段树)
Problem Description Given n integers.You have two operations:U A B: replace the Ath number by B. (in ...
- HDU 4512 吉哥系列故事——完美队形(LCIS)
Problem Description 吉哥这几天对队形比较感兴趣. 有一天,有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一 ...
随机推荐
- Android—定位
public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button ...
- Feathers UI 性能优化
Feathers UI作者写的 http://joshblog.net/2013/feathers-performance-tips/
- webForm(三)——三级联动
三级联动 首先附图一张,初步认识一下什么是三级联动: 注:选第一个后面两个变,选第二个,最后一个改变. 其次,做三级联动需要注意的方面:①DropD ...
- 大数据系统之监控系统(二)Flume的扩展
一些需求是原生Flume无法满足的,因此,基于开源的Flume我们增加了许多功能. EventDeserializer的缺陷 Flume的每一个source对应的deserializer必须实现接口E ...
- jquery $.trim()去除字符串空格详解
jquery $.trim()去除字符串空格详解 语法 jQuery.trim()函数用于去除字符串两端的空白字符. 作用 该函数可以去除字符串开始和末尾两端的空白字符(直到遇到第一个非空白字符串为止 ...
- 【转】jquery 中scrollTop在Firefox下不起作用
原文链接:http://stackoverflow.com/questions/8149155/animate-scrolltop-not-working-in-firefox Animate scr ...
- [解决]Mercurial HTTP Error 500: Access is denied on 00changelog.i
总之,用户对仓库目录要有写权限 00changelog, access is denied, hg, http error 500, mercurial, permissions, push Merc ...
- win7+ubuntu双系统 重装win7后grub修复
问题:之前安装的是win7+ubuntu双系统,重装win7后启动选项没有了,直接进入的是win7系统,无法进入ubuntu系统了. 解决办法:我们需要修复grub,将ubuntu系统重新挂载一下,具 ...
- jquery常用函数与方法
1.delay(duration,[queueName]) 设置一个延时来推迟执行队列中之后的项目.jQuery 1.4新增.用于将队列中的函数延时执行.他既可以推迟动画队列的执行,也可以用于自定义队 ...
- Google Material Design的图标字体使用教程
使用教程 1. 打开Material icons下载页 2. 选择要下载的图标 (目前不能多选>_<) 3.选择要下载的格式即可 图标字体使用教程 [方法一] STEP 1: 引入字体文件 ...