1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <cstdio> 5 #include <vector> 6 using namespace std; 7 8 typedef long long ll; 9 ll n; 10 ll arr[3005],brr[3005]; 11 ll dp[3005][3005]; 12 ll maxx; 13 14 15 int main(){ 16 ios::sync_with_stdio(false); 17 cin>>n; 18 maxx=0; 19 for(int i=1;i<=n;i++) cin>>arr[i]; 20 for(int i=1;i<=n;i++) cin>>brr[i]; 21 for(int i=1;i<=n;i++){ 22 for(int j=1;j<=n;j++){ 23 if(arr[i]==brr[j]) dp[i][j]=dp[i-1][j-1]+1; 24 else{ 25 dp[i][j]=max(dp[i-1][j],dp[i][j-1]); 26 } 27 } 28 } 29 cout << dp[n][n] << endl; 30 return 0; 31 }