UVA - 10635 Prince and Princess
来源:互联网 发布:高仿椰子 知乎 编辑:程序博客网 时间:2024/06/08 18:58
题目大意:给出n, m, k,求两个长度分别为m + 1 和 k + 1且由1~n * n组成的序列的最长公共子序列长的。
解题思路:按一般的o(n^2)的算法超时了,所以要LCS装换成LIS的算法o(nlogn)。算法仅仅是将其中的一个序列重新标号1~m,然后按最长公共子序列的方法去做。
#include <cstdio>#include <algorithm>#include <cstring>using namespace std;int main() {int T, cas = 0, pos[62600], DP[62600] = {0};scanf("%d", &T);while (T--) {int n, p, q, x, cnt = 0;scanf("%d%d%d", &n, &p, &q);memset(pos, 0, sizeof(pos));for (int i = 0; i <= p; i++) {scanf("%d", &x);pos[x] = i + 1;}for (int i = 0; i <= q; i++) {scanf("%d", &x);if (pos[x] > DP[cnt])DP[++cnt] = pos[x];elseDP[lower_bound(DP + 1, DP + 1 + cnt, pos[x]) - DP] = pos[x];}printf("Case %d: %d\n", ++cas, cnt);}return 0;}
0 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
- BeanCreationException
- Ubuntu 查看内存信息
- 黑马程序员——java基础 io 转换流的应用(InputStreamReader,OutputStreamWriter)
- 大写读入,小写输出
- 程序员:其实我个人也只是偶尔写些东西
- UVA - 10635 Prince and Princess
- WebKit渲染基础之Render树的建立
- Activity的复习以及在Onstart里设置网络连接
- 2015年Ubuntu最新Redmine的安装和配置
- Fibonacci数列
- TCP标志中的URG和PSH位
- hdu 5037 Frog(贪心)
- Object - C运行时应用(一)—— 拦截系统自带的方法交换实现
- openCL错误码