Ghosty_Neutrino @ 2024-05-21 21:02:25
#include <bits/stdc++.h>
using namespace std;
const int N=10100;
int a[N],b[N],dp[N][N];
int n,i,j;
int main(){
cin>>n;
for(i=1;i<=n;i++) scanf("%d",&a[i]);
for(i=1;i<=n;i++) scanf("%d",&b[i]);
for(i=1;i<=n;i++ ){
for(j=1;j<=n;j++){
if(a[i]==b[j]) dp[i][j]=dp[i-1][j-1]+1;
else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
}
}
printf("%d",dp[n][n]);
return 0;
}
by xudongyi1 @ 2024-05-21 21:12:14
@Rosechille_mengjing