UVa 10635 Prince and Princess 【LIS】
2017-03-01 20:11
435 查看
刘汝佳训练指南 p66
这题很好的把LCS问题转化成了LIS问题
因为两个数组保存的都是数字并且每个数组内不出现重合的数字,所以将B数组中的数字转化成在A数组中的编号然后就转化成了LIS问题了
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include <string.h>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
using namespace std;
#define MAX_N 250*250+5
#define inf 0x3f3f3f3f
#define LL long long
#define ull unsigned long long
const LL INF = 1e18;
const int mod = 1e8+7;
typedef pair<LL, LL>P;
int pos[MAX_N];
int b[MAX_N];
int g[MAX_N];
int main()
{
int T;
int ca = 1;
cin >> T;
while(T--) {
int n, p, q;
cin >> n >> p >> q;
memset(pos, 0, sizeof(pos));
memset(g, 0, sizeof(g));
for(int i=1; i<=p+1; i++) {
int x;
cin >> x;
pos[x] = i;
}
for(int i=1; i<=q+1; i++) {
int x;
cin >> x;
b[i] = pos[x];
}
int ans = 0;
int len = 0;
g[0] = b[1];
for(int i=2; i<=q+1; i++) {
if(b[i] > g[len]) {
g[++len] = b[i];
}
else {
int k = lower_bound(g, g+len, b[i]) - g;
g[k] = b[i];
}
}
printf("Case %d: %d\n", ca++, len+1);
}
}
这题很好的把LCS问题转化成了LIS问题
因为两个数组保存的都是数字并且每个数组内不出现重合的数字,所以将B数组中的数字转化成在A数组中的编号然后就转化成了LIS问题了
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include <string.h>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
using namespace std;
#define MAX_N 250*250+5
#define inf 0x3f3f3f3f
#define LL long long
#define ull unsigned long long
const LL INF = 1e18;
const int mod = 1e8+7;
typedef pair<LL, LL>P;
int pos[MAX_N];
int b[MAX_N];
int g[MAX_N];
int main()
{
int T;
int ca = 1;
cin >> T;
while(T--) {
int n, p, q;
cin >> n >> p >> q;
memset(pos, 0, sizeof(pos));
memset(g, 0, sizeof(g));
for(int i=1; i<=p+1; i++) {
int x;
cin >> x;
pos[x] = i;
}
for(int i=1; i<=q+1; i++) {
int x;
cin >> x;
b[i] = pos[x];
}
int ans = 0;
int len = 0;
g[0] = b[1];
for(int i=2; i<=q+1; i++) {
if(b[i] > g[len]) {
g[++len] = b[i];
}
else {
int k = lower_bound(g, g+len, b[i]) - g;
g[k] = b[i];
}
}
printf("Case %d: %d\n", ca++, len+1);
}
}
相关文章推荐
- uva 10635 Prince and Princess(LCS问题转化成LIS问题O(nlogn))
- UVa 10635 - Prince and Princess(LCS转LIS)
- uva 10635 Prince and Princess(LCS成问题LIS问题O(nlogn))
- uva 10635 - Prince and Princess lcs->lis 2018-2-8
- UVA 10635 Prince and Princess(LIS)
- UVA 10635 Prince and Princess【LCS 问题转换为 LIS】
- 一中OJ #1434 序列的LCS [UVa 10635 -> Prince and Princess] | 动态规划 LCS映射转换LIS | 解题报告
- UVA - 10635 Prince and Princess LCS转LIS
- UVA 10635 Prince and Princess【LCS 问题转换为 LIS】
- Prince and Princess UVA - 10635(LCS转LIS)
- Uva 10635 - Prince and Princess(LIS)
- UVA - 10635 Prince and Princess (求LIS)
- UVA 10635 - Prince and Princess LCS转化为LIS
- UVA 10635 - Prince and Princess (LCS转成LIS DP)
- dp(LCS转化成LIS)uva 10635 - Prince and Princess
- UVA 10635 - Prince and Princess LCS转化为LIS
- UVA 10635 Prince and Princess LCS转化为LIS *
- uva_10635 - Prince and Princess(LIS)
- UVA 10635 Prince and Princess DP LIS
- UVA 10635 Prince and Princess DP LIS