UVA - 10635 - Prince and Princess (LCS转化为LIS)
来源:互联网 发布:单片机编程好学吗 编辑:程序博客网 时间:2024/04/20 03:57
题目传送:UVA - 10635
思路:直接思路是两个串的LCS,不过这个题可以转化为LIS,因为说了序列中各个元素互不相同,所以可以来个映射算出第二个字符串中的字符对应第一个字符串中字符的位置(不存在即删去),然后算出这些位置的LIS即可
AC代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <map>#include <set>#include <deque>#include <cctype>#define LL long long#define INF 0x7fffffffusing namespace std;const int maxn = 250 * 250 + 10;int S[maxn], g[maxn];int num[maxn];//记录第一个数组中每个数字出现的位置 int N, p, q;int main() {int T;int cas = 1;scanf("%d", &T);while(T --) {scanf("%d %d %d", &N, &p, &q);memset(num, 0, sizeof(num));for(int i = 1; i <= p + 1; i ++) {int t;scanf("%d", &t);num[t] = i; }int n = 0;for(int i = 1; i <= q + 1; i ++) {int t;scanf("%d", &t);if(num[t] != 0) {S[n ++] = num[t];}}//n*logn求S数组的LIS for(int i = 1; i <= n; i ++) g[i] = INF;int ans = 0;for(int i = 0; i < n; i ++) {int pos = lower_bound(g + 1, g + n + 1, S[i]) - g;//n*logn查找 g[pos] = S[i];ans = max(ans, pos); }printf("Case %d: %d\n", cas ++, ans);}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 10635】【LCS转化成LIS】 Prince and Princess
- UVA 10635 Prince and Princess【LCS 问题转换为 LIS】
- UVA 10635 Prince and Princess lcs--》lis
- dp(LCS转化成LIS)uva 10635 - Prince and Princess
- uva 10635 Prince and Princess(LCS问题转化成LIS问题O(nlogn))
- 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 DP)
- 直流高压发生器启动的先后顺序
- tomcat启动错误
- 地下管线探测仪内部发射机解译分析
- 大电流发生器原理及结构化的分析
- 数字变电站的应用与发展篇
- UVA - 10635 - Prince and Princess (LCS转化为LIS)
- 变压器变比测试仪对单相变压器的原…
- 高低压CT变比测试仪对电流互感器全…
- 高压开关机械特性测试仪对直流电源…
- 耐压测试仪的用途及现场操作指南
- 了解核相仪前必须具备的常识
- 绝缘油介强度测试仪判断绝缘油试验…
- 直流高压发生器对滤波和波形的解释…
- 无线高压核相仪的核相方法及核相试…