Light_LE @ 2024-07-13 17:59:34
https://www.luogu.com.cn/record/165717129
#include<iostream>
#define maxn 10003
using namespace std;
int n;
long long a[maxn],b[maxn],dp[maxn][maxn];
int main(){
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
for(int i=1;i<=n;i++){
for(int 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]);
}
}
}
cout<<dp[n][n];
return 0;
}
by cutCUR_MC @ 2024-07-17 14:20:41
用最长上升子序列做能满分