bayerfans @ 2022-09-28 22:44:11
#include<iostream>
using namespace std;
int n,a[1000005],b[1000005];
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
int dp[n+1][n+1];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==0||j==0){
if(a[i]==b[j]){
dp[i][j]=1;
}
else if(i==0&&j==0) dp[i][j]=0;
else if(i==0) dp[i][j]=dp[i][j-1];
else dp[i][j]=dp[i-1][j];
}
else{
if(a[i]==b[j]) dp[i][j]=dp[i-1][j-1]+1;
else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
// cout<<dp[i][j]<<' ';
}
// cout<<endl;
}
cout<<dp[n-1][n-1];
return 0;
}
by vdfes @ 2022-09-28 23:03:25
@bayerfanswill 把
by bayerfans @ 2022-09-29 20:33:55
@hjy192939 谢谢谢谢