nyoj See LCS again 760 (LCS&&LIS) 好题
来源:互联网 发布:刘昱旻 知乎 编辑:程序博客网 时间:2024/04/28 20:23
See LCS again
时间限制:1000 ms | 内存限制:65535 KB
难度:3
- 描述
There are A, B two sequences, the number of elements in the sequence is n、m;
Each element in the sequence are different and less than 100000.
Calculate the length of the longest common subsequence of A and B.
- 输入
- The input has multicases.Each test case consists of three lines;
The first line consist two integers n, m (1 < = n, m < = 100000);
The second line with n integers, expressed sequence A;
The third line with m integers, expressed sequence B; - 输出
- For each set of test cases, output the length of the longest common subsequence of A and B, in a single line.
- 样例输入
5 41 2 6 5 41 3 5 4
- 样例输出
3
//函数lower_bound()在first和last中的前闭后开区间进行二分查找,//返回大于或等于val的第一个元素位置。如果所有元素都小于val,//则返回last的位置,且last的位置是越界的!返回查找元素的第一个//可安插位置,也就是“元素值>=查找值”的第一个元素的位置
#include<stdio.h>#include<string.h>#include<algorithm>#define N 100010using namespace std;int a[N];int b[N];int dp[N];int main(){int n,m,i,j;int x;while(scanf("%d%d",&n,&m)!=EOF){memset(dp,0,sizeof(dp));for(i=1;i<=n;i++){scanf("%d",&x);dp[x]=i;}int r=0;for(i=1;i<=m;i++){scanf("%d",&x);if(dp[x])b[r++]=dp[x];}int p=0;dp[p++]=b[0];for(i=1;i<r;i++){if(dp[p-1]<b[i])dp[p++]=b[i];else{x=lower_bound(dp,dp+p,b[i])-dp;dp[x]=b[i];}}printf("%d\n",p);}return 0;}
0 0
- nyoj See LCS again 760 (LCS&&LIS) 好题
- NYOJ 题目760 See LCS again(LIS求LCS)
- NYOJ 760 - See LCS again(LCS转LIS)
- Nyoj 760 See LCS again [Lcs]
- NYOJ 760 See LCS again
- NYOJ 760 See LCS again
- nyoj 760 See LCS again 最长公共子序列
- See LCS again
- ayit See LCS again
- See LCS again
- See LCS again
- See LCS again
- See LCS again
- nyistOJ-See LCS again(二分)
- LIS,LCS,一道LIS题
- LCS && LIS
- LIS+LCS~
- LCS?LIS
- Javase基础部分笔记之IO(一)
- 抓取前端渲染的页面的技术webmagic
- IOS中将字典转成模型对象
- flv、MP4 视频播放问题
- MySQL 主从复制的原理和配置
- nyoj See LCS again 760 (LCS&&LIS) 好题
- MFC控件之Edit Control
- C,C++如何和OC混用
- UIWebView根据加载的内容自动适应高度
- C++中消除CString类型字符串中的标点符号
- unmappable character for encoding ASCII
- VIM的学习总结(a Byte of VIM)
- android post HttpURLConnection乱码解决
- [leetcode]Add Binary