Topic Link: Click to open the link
Test instructions pit. Originally a look at the bare LCS, but the input in the title is not the original sequence, but the original sequence, but the position of the original sequence. For example 3 1 2 is not s[1]=3 but 1 in the sequence position is 3 i.e. s[3]=1; (s[x]=i;)
Then enter the processing on the bare LCS.
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 1<<12#define _ll __int64# Define ll long long#define INF 0x3f3f3f3f#define Mod 1000000007#define pp pair<int,int> #define ull unsigned long lon Gusing namespace Std;short dp[22][22];int s[22],t[22],n;void solve () {memset (dp,0,sizeof (DP)); for (int i=1;i<=n;i++ ) for (int j=1;j<=n;j++) if (S[i]==t[j]) Dp[i][j]=dp[i-1][j-1]+1;elsedp[i][j]=max (dp[i][j-1],dp[i-1][j]);p rintf (" %d\n ", Dp[n][n]);} int main () {int x;while (~scanf ("%d", &n)) {for (int i=1;i<=n;i++) {scanf ("%d", &x); s[x]=i;} while (~SCANF ("%d", &x)) {t[x]=1;for (int i=2;i<=n;i++) {scanf ("%d", &x); t[x]=i;} Solve ();}} return 0;}
Uva 111-history Grading (DP/LCS)