UVA - 10635 Prince and Princess
来源:互联网 发布:免费备案域名 编辑:程序博客网 时间:2024/04/29 23:26
题意:求最长公共子序列,这题涉及到将LCS转化为LIS,不然会超时,用LIS的o(nlogn)的算法,很容易理解:记录A序列的下标,然后依次填写在B序列对应的数中,然后求LIS
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 70000;const int INF = 1<<30;int g[MAXN];int m[MAXN];int d[MAXN],G[MAXN];int main(){ int t; scanf("%d",&t); for(int cas = 1; cas <= t; cas++){ int n,q,p; scanf("%d%d%d",&n,&p,&q); memset(g,0,sizeof(g)); int a; for(int i = 1; i <= p+1; i++){ scanf("%d",&a); g[a]=i; } int len=0; for(int i = 1; i <= q + 1 ;i++){ scanf("%d",&a); if(g[a]) m[len++]=g[a]; } int ans=0; for(int i = 0; i <= len; i++) G[i]=INF; for(int i = 0; i < len ; i++) { int k=lower_bound(G,G+len,m[i])-G; d[i]=k+1; G[k]=m[i]; ans=max(d[i],ans); } printf("Case %d: %d\n",cas,ans); } return 0;}
- uva 10635 Prince and Princess
- UVA 10635 Prince and Princess
- Uva-10635-Prince and Princess
- UVA 10635 Prince and Princess
- uva 10635 - Prince and Princess
- UVA 10635 Prince and Princess
- UVA 10635 Prince and Princess
- uva 10635 - Prince and Princess
- UVA - 10635 Prince and Princess
- uva 10635 - Prince and Princess
- UVA 10635 - Prince and Princess
- UVA 10635 Prince and Princess
- UVA-10635 Prince and Princess
- uva 10635 - Prince and Princess
- uva 10635 Prince and Princess
- UVA - 10635 Prince and Princess
- UVA - 10635 Prince and Princess
- UVA 10635 - Prince and Princess
- TCP连接、Http连接与Socket连接
- 行转列技巧一
- Unity 网络通信(一)Unity Network 初步
- Python配置IDE
- VS2010工程静态编译
- UVA - 10635 Prince and Princess
- C#控制TextBox滚动到底部
- ACM学习-POJ-1143-Number Game
- codeforces 160D - Edges in MST
- 买基金需要花多少钱
- 页高速缓存和页回写
- 数据库同步工具教程
- Okra App Framework 框架导航过程
- CodeSmith NetTier模板生成的代码框架用法