uva10635 Prince and Princess LCS 变 lIS
// uva10635 Prince and Princess LCS 变 lIS
// 本意求LCS,但是规模有60000多,复杂度肯定不够
// 注意如果俩个序列的值的范围相同,那么可以在一个
// 串中记录在另外一个串中的位置。这样就可以转化成
// 最长上升子序列的问题啦,复杂度是nlogn,可以ac
// 这题,还是挺有考究的价值的,很不错
// 哎,继续练吧。。。。。#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ceil(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define gcd __gcd
#define highBit(x) (1ULL<<(63-__builtin_clzll(x)))
#define popCount __builtin_popcountll
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const long double PI = acos(-1.L);template<class T> inline T lcm(const T& a, const T& b) { return a/gcd(a, b)*b; }
template<class T> inline T lowBit(const T& x) { return x&-x; }
template<class T> inline T maximize(T& a, const T& b) { return a=a<b?b:a; }
template<class T> inline T minimize(T& a, const T& b) { return a=a<b?a:b; }const int maxn = 352 * 352;
int a[maxn];
int b[maxn];
int n,p,q;
int cnt;
int dp[maxn];
const int inf = 0x3f3f3f3f;void print(int a[],int p){for (int i=1;i<=p;i++)printf("%d ",a[i]);puts("");
}void init(){scanf("%d%d%d",&n,&p,&q);memset(dp,inf,sizeof(dp));memset(b,0,sizeof(b));scanf("%d",&a[0]);int x;for (int i=1;i<=p;i++){scanf("%d",&x);a[x] = i;}scanf("%d",&b[0]);for (int i=1;i<=q;i++){scanf("%d",&x);b[i] = a[x];}
// print(a,p);
// print(b,q);cnt = 0;for (int i=1;i<=q;i++){if (b[i]){a[cnt++] = b[i];}}//print(a,p);
}void solve(){for (int i=0;i<cnt;i++){*lower_bound(dp,dp+cnt,a[i]) = a[i];}int k = lower_bound(dp,dp+cnt,inf) - dp;printf("%d\n",k+1);
}int main() {int t;//freopen("G:\\Code\\1.txt","r",stdin);scanf("%d",&t);int kase = 1;while(t--){init();printf("Case %d: ",kase++);solve();}return 0;
}
uva10635 Prince and Princess LCS 变 lIS相关推荐
- UVa10635 - Prince and Princess
/*基础:LCS*/ #include<bits/stdc++.h> using namespace std; int a[100]; int b[100]; int dp[100][10 ...
- uva10635 Prince and Princess
给你两条路径,对于每条路径上的点各不相同,请你求出两条路径最长公共部分的长度. Input 第一行是数据组数t 每组数据的第一行包含三个数,n,p,q.其中路径上的点的大小不会超过n^2. 第二行包含 ...
- HDU 4685 Prince and Princess(二分匹配加点建图+强连通分量)
题目链接 Problem Description There are n princes and m princesses. Princess can marry any prince. But pr ...
- H - Prince and Princess 计蒜客 - 42402
H - Prince and Princess 计蒜客 - 42402 题意: 你现在要寻找公主,有三种人,第一种是说真话的人(至少为1,因为公主是说真话的人),第二种人是只会说假话的,第三种是胡说八 ...
- UVA 10635 Prince and Princess
题意: 求两数字串的最长公共子序列(LCS). 思路: LCS的时间复杂度为O(nn),因为数据量大,所以会超时. 又因为数字串互不相同,所以可以LCS转LIS(最长上升子序列),LIS有时间复杂度O ...
- HDU4685:Prince and Princess(二分图匹配+tarjan)
Prince and Princess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- Prince and Princess问题解决
摘要 这是突然看到的一个非常有意思的题,是ACM-ICPC的原题,在这里稍微做一些分析,希望对大家有帮助. Prince and Princess 题面 王子m和公主Hff相爱,想要娶公主.虽然公主非 ...
- uva 10635 Prince and Princess(LCS成问题LIS问题O(nlogn))
标题效果:有两个长度p+1和q+1该序列.的各种元素的每个序列不是相互同.并1~n^2之间的整数.个序列的第一个元素均为1. 求出A和B的最长公共子序列长度. 分析:本题是LCS问题,可是p*q< ...
- UVa 10635 (LIS+二分) Prince and Princess
题目的本意是求LCS,但由于每个序列的元素各不相同,所以将A序列重新编号{1,2,,,p+1},将B序列重新编号,分别为B中的元素在A中对应出现的位置(没有的话就是0). 在样例中就是A = {1 7 ...
最新文章
- to_excel() got an unexpected keyword argument ‘sheetname‘
- 腾讯云发布微瓴开放平台LinkBase,助力智慧建筑产业生态全面升级
- rsyslog+loganalyzer+evtsys搭建集中式监控系统
- Python读取.edf格式脑电数据文件
- 不想当亿万富翁的程序员不是好老板
- MySQL 高级 函数
- unix高级编程apue.h问题
- matlab提速技巧(自matlab帮助文件)
- input发送a.jax_与时俱进:在JAX-RS API中采用OpenAPI v3.0.0
- 我的Serverless实战——引领云计算的下一个十年
- SVD(6.5.1定理证明观察3)
- 深层神经网络——总结
- 手把手教你学习网络编程(1)
- mysql 小类型_mysql数据类型
- android_5.0简介
- Windows系统如何关闭防火墙保姆式教程,超详细
- 华为云为基因检测保驾护航,助力健康行业发展
- 没学过Word排版的看过来 Word排版技巧分享
- C语言简单程序——解二元一次方程
- 【数据库】python连接数据库(保姆式服务,一口一口喂啊歪)
热门文章
- ES6、ES7、ES8、ES9、ES10新特性一览
- android三星note20.6,三星Galaxy Note 20 Ultra依旧是“安卓机皇”,用过的都说好
- 扩展欧几里得的几个定理以及证明
- 2021年R1快开门式压力容器操作考试报名及R1快开门式压力容器操作考试试题
- DataStage 简介
- git远程仓库的创建(养成好的习惯,小马教你提交代码到远程仓库中)
- QQ秀已然式微,而同时迭代的厘米秀正在雄起。
- python制作动态时钟_python+pygame制作一个可自定义的动态时钟和详解
- Python基本手册
- 记-阿里开发手册规范(JAVA)