【UVA】10635 Prince and Princess(LCS)
题目
传送门:QWQ
分析
水题。$ O(nlogn) $的LCS
代码
#include <bits/stdc++.h>
using namespace std;
const int maxn=*, INF=1e9;
int S[maxn], g[maxn], d[maxn];
int num[maxn];
int main(){
int T; scanf("%d",&T);
for(int kase=;kase<=T;kase++){
int N,p,q,x;
scanf("%d%d%d",&N,&p,&q);
memset(num,,sizeof(num));
for(int i=;i<=p+;i++){scanf("%d",&x); num[x]=i;}
int n=;
for(int i=;i<q+;i++){scanf("%d",&x);if(num[x]) S[++n]=num[x];} for(int i=;i<=n;i++) g[i]=INF;
int ans=;
for(int i=;i<=n;i++)
{
int k=lower_bound(g+,g++n,S[i])-g;
d[i]=k; g[k]=S[i];
ans=max(ans,d[i]);
}
printf("Case %d: %d\n",kase,ans);
}
return ;
}
【UVA】10635 Prince and Princess(LCS)的更多相关文章
- 【转】最长公共子序列(LCS),求LCS长度和打印输出LCS
求LCS的长度,Java版本: public static int LCS(int[]a,int[] b) { int [][]c=new int[a.length+1][b.length+1]; f ...
- uva 10635 Prince and Princess(LCS成问题LIS问题O(nlogn))
标题效果:有两个长度p+1和q+1该序列.的各种元素的每个序列不是相互同.并1~n^2之间的整数.个序列的第一个元素均为1. 求出A和B的最长公共子序列长度. 分析:本题是LCS问题,可是p*q< ...
- Uva 10635 Prince and Princess (LCS变形LIS)
直接LCS是时间复杂度是O(p*q)的,但是序列元素各不相同,只要把其中一个序列映射成有序的, 另外一个序列再做相同的映射,没有的直接删掉,就变成了求另一个序列LIS. #include<bit ...
- UVA - 10635 Prince and Princess(LCS,可转化为LIS)
题意:有两个长度分别为p+1和q+1的序列,每个序列中的各个元素互不相同,且都是1~n2的整数.两个序列的第一个元素均为1.求出A和B的最长公共子序列长度. 分析: A = {1,7,5,4,8,3, ...
- 【UVa】1606 Amphiphilic Carbon Molecules(计算几何)
题目 题目 分析 跟着lrj学的,理解了,然而不是很熟,还是发上来供以后复习 代码 #include <bits/stdc++.h> using namespace std; ; stru ...
- 【UVa】1343 The Rotation Game(IDA*)
题目 题目 分析 lrj代码.... 还有is_final是保留字,害的我CE了好几发. 代码 #include <cstdio> #include <algorit ...
- 【UVa】11212 Editing a Book(IDA*)
题目 题目 分析 get一下IDA*的技巧,感觉总体来说不难,主要是剪枝比较难想. 这是lrj的代码,比较通俗易懂,关键就是选定一个区间再取出来,插入到一个位置,接下来转移到这个状态. ...
- 【UVA】12504 Updating a Dictionary(STL)
题目 题目 分析 第一次用stringstream,真TMD的好用 代码 #include <bits/stdc++.h> using namespace std; int ...
- luogu P1439 【模板】最长公共子序列(LCS)
题目qwq (第一道蓝题) 先把第一个序列每个数出现的顺序记下来(数字本身不用记), 然后第二个序列的每个数都对照它的顺序,这样只要得到一个升序的序列就行了qwq 如果遇到出现顺序在前面的数,就用二分 ...
随机推荐
- 在 php 中使用 strace、gdb、tcpdump 调试工具
转自:http://www.syyong.com/php/Using-strace-GDB-and-tcpdump-debugging-tools-in-PHP.html 在 php 中我们最常使用调 ...
- H5 canvas控制坦克移动
接着上一篇(http://www.cnblogs.com/zhouhuan/p/H5_tankgame.html),这一篇研究一下怎么响应玩家的操作让坦克进行相应的移动. 1. 了解keydown ...
- 遗传算法 Genetic Algorithm
2017-12-17 19:12:10 一.Evolutionary Algorithm 进化算法,也被成为是演化算法(evolutionary algorithms,简称EAs),它不是一个具体的算 ...
- Numpy np.array 相关常用操作
https://www.cnblogs.com/oftenlin/p/7856389.html
- UVA-11761-马尔可夫/记忆化搜索
https://vjudge.net/problem/UVA-11762 给出一个整数n,每次随机挑选一个小于等于n的素数,如果是n的因子,n变为n/x ,否则不变,问n变为1的期望挑选次数. f[i ...
- HDU1598 并查集+贪心
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- StringUtils工具类的isBlank()方法使用说明
- Java语言发展史和eclipse配置
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- Class.getResource()方法的使用
我们之前使用路径总是有点不知道怎么用,发现别人使用Class.getResource()方法,好像挺不错的样子.于是看看博客,简单学习下. 参考链接:http://blog.csdn.net/lcj8 ...
- 深度学习(七十一)darknet 源码阅读
深度学习(七十一)darknet 源码阅读