Reobrok_Kk @ 2020-08-10 16:08:46
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int a[5001],b[5001];
int f[5001][5001];
int max(int x,int y){return x>y?x:y;}
int main(){
int n;
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]) f[i][j]=f[i-1][j-1]+1;
if(a[i]!=b[j]) f[i][j]=max(f[i][j-1],f[i-1][j]);
}
cout<<f[n][n]<<endl;
return 0;
}
by 清风雪月 @ 2021-08-27 19:56:08
考古,没想到我的代码跟这个一模一样
by __PJL__ @ 2024-06-11 16:24:45
246810