uva 10635 LCS转LIS
这道题两个数组都没有重复的数字,用lcs的nlogn再适合不过了
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define MAXN 1005
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue
#define INF 0x3f3f3f3f int n,m,v; int q,p,top; int a[*],b[*],c[*],pos[*],stk[*]; void lis(int len)
{
mem(stk,);
top = ;
stk[] = -;
for(int i=;i<=len;i++)
{
if(c[i]>stk[top])
{
stk[++top] = c[i];
}
else
{
int lo=,hi=top,mid;
while(lo<=hi)
{
mid = (lo+hi)>>;
if(c[i]>stk[mid]) lo = mid+;
else hi = mid -;
}
stk[lo] = c[i];
}
}
} int main()
{
int i,j;
int t,kase=;
sf("%d",&t);
while(t--)
{
sf("%d%d%d",&n,&p,&q);
mem(pos,);
mem(c,);
v=;
for(i=;i<=p+;i++)
{
sf("%d",&a[i]);
pos[a[i]] = i;
}
for(i=;i<=q+;i++)
{
sf("%d",&b[i]);
if(pos[b[i]]) c[v++] = pos[b[i]];
}
lis(v);
pf("Case %d: %d\n",kase++,top);
}
}
uva 10635 LCS转LIS的更多相关文章
- O(nlogn)实现LCS与LIS
序: LIS与LCS分别是求一个序列的最长不下降序列序列与两个序列的最长公共子序列. 朴素法都可以以O(n^2)实现. LCS借助LIS实现O(nlogn)的复杂度,而LIS则是通过二分搜索将复杂度从 ...
- 最长公共子序列-LCS问题 (LCS与LIS在特殊条件下的转换) [洛谷1439]
题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入 第一行是一个数n, 接下来两行,每行为n个数,为自然数1-n的一个排列. 输出 一个数,即最长公共子序列的长度 输入样例 5 ...
- BZOJ4990 (LCS转LIS)
题面 https://www.lydsy.com/JudgeOnline/problem.php?id=4990 分析 首先可以看出一个简单的DP dp[i][j]表示序列a前i个与序列b前j个连线数 ...
- UVA 10635 Prince and Princess【LCS 问题转换为 LIS】
题目链接: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19051 题意: 有两个长度分别为p+1和q+1的由1到n2 ...
- UVA 10635 - Prince and Princess LCS转化为LIS
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- Uva 10635 - Prince and Princess LCS/LIS
两个长度分别为p+1和q+1的由1到n2之前的整数组成的序列,每个序列的元素各不相等,两个序列第一个元素均为1.求两个序列的最长公共子序列 https://uva.onlinejudge.org/in ...
- 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 难度: 2
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA - 10635 LIS LCS转换
白书例题,元素互不相同通过哈希转换为LIS求LCS #include<iostream> #include<algorithm> #include<cstdio> ...
随机推荐
- 【spring boot】FilterRegistrationBean介绍
前言 以往的javaee配置过滤器是在web.xml中配置的,如下代码 <filter> <filter-name>TestFilter</filter-name> ...
- 八大排序算法的python实现(七)基数排序
代码: #coding:utf-8 #author:徐卜灵 import math #print math.ceil(3.2) 向上取整4.0 #print math.floor(3.2) 向下取整3 ...
- python3+Django1.11+mysql5.7 MySQL DB API Drivers
The Python Database API is described in PEP 249. MySQL has three prominent drivers that implement th ...
- 从pg_hba.conf文件谈谈postgresql的连接认证
最近一直在弄postgresql的东西,搭建postgresql数据库集群环境什么的.操作数据库少不得要从远程主机访问数据库环境,例如数据库管理员的远程管理数据库,远程的客户存取数据库文件. 而在po ...
- 关于:“无法序列化会话状态。在“StateServer”或“SQLServer”模式下,...的问题
关于:“无法序列化会话状态.在“StateServer”或“SQLServer”模式下,...的问题 错误描述: 无法序列化会话状态.在“StateServer”或“SQLServer”模式下,ASP ...
- UVA - 10298 后缀数组(仅观赏)
题意:求最小循环节 \(KMP\)可以20ms通过,而\(da\)实现的后缀数组并无法在3000ms内通过 听说要用\(dc3\)才勉强卡过,这里仅列出\(da\)实现 #include<ios ...
- Spring 操作 jdbc 链接数据库
1. 新建资源文件 db.properities jdbc.user=root jdbc.password=root jdbc.driverClass=com.mysql.jdbc.Driver jd ...
- poj2718
一.题意:给定一串数字,数字没有重复,个数为2~10个.求这些数字分为两份,组合成的两个数的差最小是多少 二.思路:首先可以肯定的是,将这n个数平均分成两份,所得到的最小差一定在其某个组合当中.因此可 ...
- 数据插入INSERT
一.INSERT SELECT :将查询的数据直接插入 特点: 1.一次性插入所有查询出来的数据. 2.数据原子性,有一个失败全部失败. 3.没有指定的列加默认值或NULL,都没有就报错. 二.INS ...
- 金融量化分析-python量化分析系列之---使用python获取股票历史数据和实时分笔数据
财经数据接口包tushare的使用(一) Tushare是一款开源免费的金融数据接口包,可以用于获取股票的历史数据.年度季度报表数据.实时分笔数据.历史分笔数据,本文对tushare的用法,已经存在的 ...