UVA 10635 Prince and Princess (LCS优化转LIS)
来源:互联网 发布:微信淘宝秒杀是真的吗 编辑:程序博客网 时间:2024/03/28 22:15
题意:求两个串的最长公共子序列 LCS。
思路:数据量比较大,O(n^2)的dp不够快。但每组数据中的数各不相同,可以利用这一点转化成求最大上升子序列 LIS
就样例来说 A{1 7 5 4 8 3 9}, B{1 4 3 5 6 2 8 9},按照A的顺序进行映射:A{1,2,3,4,5,6,7} B{1,4,6,3,0,0,5,7}
于是问题转化为求B的LIS,可以在O(nlogn)求出。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N=255*255;int data[N],stack[N],hash[N];int main (){int T;scanf("%d",&T);for (int Cas=1;Cas<=T;Cas++){memset(hash,0,sizeof(hash));int n,p,q;scanf("%d%d%d",&n,&p,&q);int i,id=0,x,len=0;for (i=1;i<=p+1;i++){scanf("%d",&x);hash[x]=i;}for (i=0;i<=q;i++) {scanf("%d",&x);if (hash[x])data[id++]=hash[x];}stack[0]=data[0];for (i=1;i<id;i++)if (data[i]>stack[len])stack[++len]=data[i];else{int pos=lower_bound(stack,stack+len,data[i])-stack;stack[pos]=data[i];}printf("Case %d: %d\n",Cas,len+1);}return 0;}
- UVA 10635 Prince and Princess (LCS优化转LIS)
- UVA 10635 Prince and Princess lcs--》lis
- Uva - 10635 - Prince and Princess(LCS转LIS)
- UVa 10635 Prince and Princess / LCS 转 LIS
- uva 10635Prince and Princess (LCS转LIS)
- UVA - 10635 Prince and Princess LCS转LIS
- UVa 10635 - Prince and Princess(LCS转LIS)
- UVA 10635 Prince and Princess(LCS转LIS)
- uva 10635 Prince and Princess(LCS转LIS~)
- uva 10635 Prince and Princess (将LCS 转化为 LIS)
- UVA 10635 - Prince and Princess LCS转化为LIS
- UVA 10635 - Prince and Princess (LCS转成LIS DP)
- UVA - 10635 - Prince and Princess (LCS转化为LIS)
- UVA 10635 - Prince and Princess ( LCS 转换为LIS )
- uva 10635-Prince and Princess 【LIS 求解 LCS】
- uva-10635 Prince and Princess LCS转化为LIS
- UVA 10635 Prince and Princess【LCS 问题转换为 LIS】
- 【UVA 10635】【LCS转化成LIS】 Prince and Princess
- Thread.Sleep
- bst实现C++类模版
- linux 登录模式的修改 -bash-3.2$ [user@localhost ~]#
- weblogic后台日志输出到文件中
- 多线程和多进程的区别(小结)
- UVA 10635 Prince and Princess (LCS优化转LIS)
- Codeforces 4C Registration System map的应用
- Javap使用说明
- /bin/sh: root: command not found
- 固定公式法计算EV
- 精确获取时间(QueryPerformanceCounter)
- uva 11991
- boost之shared_ptr的一个计数小问题
- C#面试基础问题