Topic Transfer: UVA-10635
Idea: The direct idea is two strings of LCS, but this problem can be converted to LIS, because said the sequence of elements are different, so you can map out the second character in the string corresponding to the position of the characters in the first string (does not exist is deleted), and then calculate the location of the LIS can
AC Code:
#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 = [+] + 10;int S[MAXN], G[maxn];int num[maxn];//records the position of each digit in the first array int N, p, q;int main () {int t;int cas = 1;sca NF ("%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 for an S array of lis for (int i = 1; I <= n; i + +) g[i] = inf;int ans = 0;for (int i = 0; i < n; i + +) {int pos = Lower_bo und (g + 1, G + N + 1, s[i])-G;//n*logn find G[pos] = S[i];ans = max (ans, POS); }printf ("Case%d:%d\n", CAs + +, ans);} return 0;}
Uva-10635-prince and Princess (LCS converted to LIS)