song__stanford @ 2023-07-30 20:22:05
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[50005],b[50005];
ll n;
ll f[5005][5005];
int main(){
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;
else f[i][j]=max(f[i-1][j],f[i][j-1]);
}
}
cout<<f[n][n];
return 0;
}
by ybc2025chenyuyang @ 2023-07-30 23:12:46
这个题
by ybc2025chenyuyang @ 2023-07-30 23:13:04
@song__stanford
by song__stanford @ 2023-07-31 09:12:07
哦
by qiujun @ 2023-08-08 09:02:44
得用滚动数组,明显二维数组会炸,就算你的f只开5005* 5005所消耗的空间也达到了191mb