直接LCS是时间复杂度是O(p*q)的,但是序列元素各不相同,只要把其中一个序列映射成有序的,

另外一个序列再做相同的映射,没有的直接删掉,就变成了求另一个序列LIS。

#include<bits/stdc++.h>
using namespace std; int read()
{
char c; while(c=getchar(),c<''||c>'');
int re = c-'';
while(c=getchar(),c>=''&&c<='') re = re*+c-'';
return re;
} const int maxn = *; int mp[maxn]; int S[maxn],g[maxn]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int T; scanf("%d",&T);
for(int ks = ; ks <= T; ks++){
int n, p, q; scanf("%d%d%d",&n,&p,&q);
memset(mp,-,sizeof(mp));
for(int i = ; i <= p; i++) {
mp[read()] = i;
}
int c = ;
for(int i = ; i <= q; i++){
int x = mp[read()];
if(~x){
S[c++] = x;
}
}
memset(g,0x3f,sizeof(int)*(c+));
int ans = ;
for(int i = ; i < c; i++){
int k = lower_bound(g+,g++i,S[i])-g;
g[k] = S[i];
ans = max(ans,k);
}
printf("Case %d: %d\n",ks,ans);
}
return ;
}

Uva 10635 Prince and Princess (LCS变形LIS)的更多相关文章

  1. UVA - 10635 Prince and Princess LCS转LIS

    题目链接: http://bak.vjudge.net/problem/UVA-10635 Prince and Princess Time Limit: 3000MS 题意 给你两个数组,求他们的最 ...

  2. uva 10635 - Prince and Princess(LCS)

    题目连接:10635 - Prince and Princess 题目大意:给出n, m, k,求两个长度分别为m + 1 和 k + 1且由1~n * n组成的序列的最长公共子序列长的. 解题思路: ...

  3. UVA 10635 - Prince and Princess LCS转化为LIS

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  4. Uva 10635 - Prince and Princess LCS/LIS

    两个长度分别为p+1和q+1的由1到n2之前的整数组成的序列,每个序列的元素各不相等,两个序列第一个元素均为1.求两个序列的最长公共子序列 https://uva.onlinejudge.org/in ...

  5. UVA 10635 Prince and Princess【LCS 问题转换为 LIS】

    题目链接: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19051 题意: 有两个长度分别为p+1和q+1的由1到n2 ...

  6. uva 10635 Prince and Princess(LCS成问题LIS问题O(nlogn))

    标题效果:有两个长度p+1和q+1该序列.的各种元素的每个序列不是相互同.并1~n^2之间的整数.个序列的第一个元素均为1. 求出A和B的最长公共子序列长度. 分析:本题是LCS问题,可是p*q< ...

  7. Uva 10635 - Prince and Princess 问题转化,元素互不相同(在自身序列中独特)的两个数列的LCS,LIS 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  8. UVA - 10635 Prince and Princess(LCS,可转化为LIS)

    题意:有两个长度分别为p+1和q+1的序列,每个序列中的各个元素互不相同,且都是1~n2的整数.两个序列的第一个元素均为1.求出A和B的最长公共子序列长度. 分析: A = {1,7,5,4,8,3, ...

  9. UVA 10635 Prince and Princess—— 求LCS(最长公共子序列)转换成 求LIS(最长递增子序列)

    题目大意:有n*n个方格,王子有一条走法,依次经过m个格子,公主有一种走法,依次经过n个格子(不会重复走),问他们删去一些步数后,重叠步数的最大值. 显然是一个LCS,我一看到就高高兴兴的打了个板子上 ...

随机推荐

  1. 模块 DLL C:\WINDOWS\system32\inetsrv\aspnetcore.dll 未能加载。返回的数据为错误信息。

    更新了win10的版本后,就启动原来的iis发布的程序 程序池就自动关闭.后来 启动网站 iis程序池自动关闭. 在为应用程序池“.NET v4.5”提供服务的工作进程“21908”中,协议“http ...

  2. 滴滴Booster移动APP质量优化框架 学习之旅

    推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 一.Booster简介 Booster是滴滴最近开源一个的移动应 ...

  3. 移动端tab目录(有待完善)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  4. 在Visual Studio中编译Linux的一些问题

    相对路径: 在windows下,和当前文件同一个目录下的引用会这么写: #include "SubDirectory\header.h" 或者 #include "Sub ...

  5. python3编程技巧二——如何在列表、字典、集合 中根据条件筛选数据

    一.列表筛选数据 # coding=utf-8 from random import randint # 创建随机列表 l = [randint(-10, 10) for i in range(10) ...

  6. JDBC基础原理

    一.DCL(了解) -- 1. 创建用户CREATE USER 'zhangsan'@'%' IDENTIFIED BY 'zhangsan';-- 2. 用户授权GRANT ALL ON heima ...

  7. JDK12下的ArrayList源码解读 与 Vector的对比

    ArrayList源码阅读. //测试代码实现如下 private static void arrayList() { ArrayList<String> list = new Array ...

  8. Linux下FTP用户的使用配置

    1.创建本地账户,用户名为自己的姓名拼音,使用本地用户测试,从以下几个方面来观察,账户 .密码.访问目录(可否查看上级目录) .上传下载的权限.

  9. Codeforces Round #527 -A. Uniform String(思维)

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  10. DotNetAnywhere

    DotNetAnywhere:可供选择的 .NET 运行时   原文 : DotNetAnywhere: An Alternative .NET Runtime作者 : Matt Warren译者 : ...