uva 10635 Prince and Princess(LCS转LIS~)
来源:互联网 发布:营销软件名字 编辑:程序博客网 时间:2024/04/26 16:42
这是个求最长公共子序列的题,最后转化成了最长上升子序列的题,使用了O(nlogn)的算法,贴个讲解的链接
http://blog.csdn.net/shuangde800/article/details/7474903
第一次用lower_bound这个函数,觉得好奇怪,不是要用迭代器的嘛,竟然可以直接用地址,,,呃呃呃反正不太懂
多多练习,,还是不熟啊,都是看题解的
#include <algorithm>#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int maxn = 250 + 10;const int INF = 1000000000;int num[maxn * maxn], princess[maxn * maxn], g[maxn * maxn], d[maxn * maxn];int main(){ int t, n, p, q, i, temp; scanf("%d", &t); for (int kase = 1; kase <= t; kase++) { scanf("%d%d%d", &n, &p, &q); memset(num, 0, sizeof(0)); for (i = 1; i <= p + 1; i++) { scanf("%d", &temp); num[temp] = i; } int m = 1; for (i = 1; i <= q + 1; i++) { scanf("%d", &temp); if (num[temp]) princess[m++] = num[temp]; } for (i = 1; i < m; i++) g[i] = INF; int ret = -1; for (i = 1; i < m; i++) { int k = lower_bound(g + 1, g + m, princess[i]) - g; d[i] = k; g[k] = princess[i]; ret = max(ret, d[i]); } printf("Case %d: %d\n", kase, ret); } return 0;}
阅读全文
0 0
- Uva - 10635 - Prince and Princess(LCS转LIS)
- UVa 10635 - Prince and Princess(LCS转LIS)
- uva 10635 Prince and Princess(LCS转LIS~)
- UVA 10635 Prince and Princess lcs--》lis
- UVA 10635 Prince and Princess (LCS优化转LIS)
- UVa 10635 Prince and Princess / LCS 转 LIS
- uva 10635Prince and Princess (LCS转LIS)
- UVA - 10635 Prince and Princess LCS转LIS
- UVA 10635 Prince and Princess(LCS转LIS)
- UVA - 10635 - Prince and Princess (LCS转化为LIS)
- UVA 10635 - Prince and Princess ( LCS 转换为LIS )
- uva 10635 Prince and Princess (将LCS 转化为 LIS)
- UVA 10635 - Prince and Princess LCS转化为LIS
- UVA 10635 - Prince and Princess (LCS转成LIS DP)
- uva 10635-Prince and Princess 【LIS 求解 LCS】
- uva-10635 Prince and Princess LCS转化为LIS
- UVA 10635 Prince and Princess【LCS 问题转换为 LIS】
- 【UVA 10635】【LCS转化成LIS】 Prince and Princess
- spring boot 使用@ConfigurationPropertiesu将配置自动封装成实体类
- dubbo测试项目搭建
- java 反射(二) 反射中Class常见的方法和属性
- 病毒入侵的故事—BBC细胞的暗战The Hidden Life of the Cell
- NOIp2014提高组 寻找道路->蜜汁最短路
- uva 10635 Prince and Princess(LCS转LIS~)
- MySQL优化系列(八)--锁机制超详细解析(锁分类、事务并发、引擎并发控制)
- number输入框限制输入数字位数、字体随数字长度变化
- 比较重量(华为面试题改)链式前向星的使用+bfs
- Xpath语法与lxml库的用法
- C实现moore边界跟踪算法
- 【数位DP+记忆化搜索】不要62 HDU
- javax.xml.parsers.ParserConfigurationException: Feature 'http://apache.org/xml/features/xinclude' is
- 设计模式 -- 行为型模式