uva10635(LCS转换为求LIS)
2016-05-06 21:03
330 查看
链接:点击打开链接
题意:求两个串的最长公共子序列(两个串长度最大为250*250)
代码:
题意:求两个串的最长公共子序列(两个串长度最大为250*250)
代码:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; const int INF=0x3f3f3f3f; int a[100005],b[100005],dp[100005],pos[100005]; int main(){ //样例A={1,7,5,4,8,3,9},B={1,4,3,5,6,2,8,9} int t,n,p,q,i,j,cas; //因为A,B中,每个数字只出现一次,因此对A,B中的 scanf("%d",&t); //数进行重新编号,编号后 for(cas=1;cas<=t;cas++){ //A={0,1,2,3,4,5,6},B={0,3,5,2,-1,-1,4,6} scanf("%d%d%d",&n,&p,&q); //-1代表没出现过,因此就变成求数组B的LIS memset(dp,INF,sizeof(dp)); //因此就从O(n*n)的LCS转换成O(n*logn)的LIS memset(pos,-1,sizeof(pos)); for(i=0;i<p+1;i++){ scanf("%d",&a[i]); pos[a[i]]=i; } for(i=0;i<q+1;i++){ scanf("%d",&b[i]); b[i]=pos[b[i]]; } for(i=0;i<q+1;i++) *lower_bound(dp,dp+q+1,b[i])=b[i]; printf("Case %d: %d\n",cas,lower_bound(dp,dp+q+1,INF)-dp); } return 0; }
相关文章推荐
- [svc][op]SSH公钥认证+优化
- Java 8从永久代到metaspace
- Common used English
- HDU 专题分类
- shell---消除文件后缀四种方法
- Object Detection with DPM
- nyoj55懒省事的小明(STL优先队列)
- 本文建模系列值三:LDA感悟
- poj 1321棋盘问题(补充)
- IOS自动释放原理及详解
- C经典 结构图初始化三种方式
- 文本建模系列之二:pLSA
- MAC OS X 系统怎么样?
- java底层知识(5)--递归与尾递归总结
- 文本建模系列之一:LSA
- fwrite,fread and fprintf,fscanf的一些使用体会
- java----map,set,hash的源码分析---篇1
- mac常用快捷键
- 幻方 C代码
- JAVA+CKEditor+CKFinder 配置异常解决方案