lcs nlogn 算法
来源:互联网 发布:如何下载excel2007软件 编辑:程序博客网 时间:2024/06/03 21:13
#include <map>#include <queue>#include <cmath>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define maxn 1005using namespace std;int a[maxn],dp[maxn];vector<int>location[26];char s1[maxn],s2[maxn];void init(){ for(int i=0;i<=maxn;++i) a[i]=dp[i]=0;}void LCS(){ init(); int i,j,k,w,ans,l,r,mid; int lena=strlen(s1),lenb=strlen(s2); for(i=0;i<26;i++)location[i].clear(); for(i=lenb-1;i>=0;--i)location[s2[i]-'a'].push_back(i); for(i=0,k=0;s1[i];i++) for(j=0;j<location[w=s1[i]-'a'].size();++j,++k) a[k]=location[w][j]; dp[1]=a[0]; dp[0]=-1; for(i=ans=1;i<k;++i){ l=0;r=ans; while(l<=r){ mid=(l+r)>>1; if(dp[mid]>=a[i])r=mid-1; else l=mid+1; } if(r==ans) ans++,dp[r+1]=a[i]; else if(dp[r+1]>a[i])dp[r+1]=a[i]; } cout<<ans<<'\12';}int main(){ while(scanf("%s%s",s1,s2)!=EOF)LCS(); return 0;}
0 0
- nLogn LCS 算法总结
- lcs nlogn 算法
- O(nlogn)LIS及LCS算法
- lcs 最长公共子序列 O(nlogn)算法
- 最长公共子序列 (lcs)O(nlogn)算法
- LCS最大公共子序列O(nlogn)算法
- JZOJ4721 NlogN的LCS
- LCS时间复杂度O(NlogN)
- 【CDOJ】柱爷大战滑稽王 【LCS转LIS问题 解决Lcs问题的O(NlogN)算法】
- LIS、LCS 的o(n^2) 和 o(nlogn)算法小结
- hdu 1159 dp lcs nlogn解法
- UVa 10635 Prince and Princess(LCS nlogn)
- O(nlogn)实现LCS与LIS
- LCS时间复杂度O(NlogN) (LCS 转 LIS)
- LCS算法
- LCS算法
- LCS 算法
- LCS算法
- 一个Java音乐播放器
- 【学习anroid编译】关于运行android模拟器
- eclipse aidl.exe error while creating directories
- 解决Win10下Android Studio terminal无法输入的问题
- ios多线程操作(十二)—— 自定义NSOperation实现网络下载后回调
- lcs nlogn 算法
- OpenStack 安装教程(使用Fuel )
- 织梦后台jpeg格式图片没法上传,图片浏览器中没法查看预览
- spring mvc中的@PathVariable
- CentOS安装软件<一> MYSQL
- c++(1)
- BruteForceMatcher无法找到
- 什么是P问题、NP问题和NPC问题
- 关于根据oracle字段长度更新字段值