uva 10635 Prince and Princess
来源:互联网 发布:excel破解密码软件 编辑:程序博客网 时间:2024/04/25 16:04
题意:求最长公共上升子序列。
n^2的算法会超时。考虑是最长公共子子序列可以看成最长上升序列来做(只不过是以上一个字符给出的大小关系,以前我不知道最长公共子序列时的做法,不过当前我并不知道最长上升子序列的olog(n)做法,所以没有意识到这点。),所以我用map建立了大小关系,然后进行跟一个nlog(n)的最长上升子序列就可以过了。
#include <iostream>#include <cstdio>#include <cstring>#include <map>#include <algorithm>using namespace std;map<int,int> hash;int cnt,dp[70000];void fun(int);int main(){ int t,t_cnt=0; scanf("%d",&t); while(t--) { cnt=-1; hash.clear(); int k,n,m,temp; scanf("%d%d%d",&k,&n,&m); for(int i=0;i<n+1;i++) { scanf("%d",&temp); hash.insert(pair<int,int>(temp,i)); } for(int i=0;i<m+1;i++) { scanf("%d",&temp); fun(hash[temp]); } printf("Case %d: %d\n",++t_cnt,cnt+1); } return 0;}void fun(int x){ if(cnt==-1||dp[cnt]<x) dp[++cnt]=x; else { int pos=lower_bound(dp,dp+cnt,x)-dp; dp[pos]=x; }}
- 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
- HIVE中UDTF编写和使用
- SVN switch 用法详解
- C# regex replace
- 解决透明static控件重叠问题
- linux系统dig和nslookup的安装
- uva 10635 Prince and Princess
- 为什么项目经理拿的钱比程序员多?
- ubuntu下安装xcfe4桌面环境
- SqlServerHelper类,整理微软提供的helper
- .Net 登录窗口
- php画图表
- confuse about thinking in English
- android资源下载
- javascript 两个日期相减