//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%lld",&a)
#define sii(a,b) scanf("%lld %lld",&a,&b)
#define siii(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pi(a) printf("%lld\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 50
#define MOD 1000000007
ll n,m,b[MAX],a[MAX],dp[MAX][MAX];
int main(){
ll r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
si(n);
f(i,0,n){
si(x);
a[x-1]=i;
}
while(si(x)!=EOF){
b[x-1]=0;
f(i,1,n){
si(x);
b[x-1]=i;
}
clr(dp,0);
f(i,0,n+1){
f(j,0,n+1){
if(i==0 || j==0)
dp[i][j]=0;
else if(a[i-1]==b[j-1])
dp[i][j]=dp[i-1][j-1]+1;
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
cout<<dp[n][n]<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%lld",&a)
#define sii(a,b) scanf("%lld %lld",&a,&b)
#define siii(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pi(a) printf("%lld\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 50
#define MOD 1000000007
ll n,m,b[MAX],a[MAX],dp[MAX][MAX];
int main(){
ll r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
si(n);
f(i,0,n){
si(x);
a[x-1]=i;
}
while(si(x)!=EOF){
b[x-1]=0;
f(i,1,n){
si(x);
b[x-1]=i;
}
clr(dp,0);
f(i,0,n+1){
f(j,0,n+1){
if(i==0 || j==0)
dp[i][j]=0;
else if(a[i-1]==b[j-1])
dp[i][j]=dp[i-1][j-1]+1;
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
cout<<dp[n][n]<<endl;
}
return 0;
}
No comments:
Post a Comment