huangzihao2025 @ 2023-07-09 22:51:51
#include<bits/stdc++.h>
using namespace std;
namespace hzh{
int n,a[100005],b[100005];
long long f[10005][10005];
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 if(a[i]!=b[j])
{
f[i][j]=max(f[i-1][j],f[i][j-1]);
}
}
}
cout<<f[n][n];
return 0;
}
}
int main(){hzh::main();}
by huangzihao2025 @ 2023-07-09 22:53:01
mle了5个点
by I_never_left @ 2023-07-10 06:40:33
@huangzihao2025 long long f[10005][10005];
这样肯定炸,换个思路
by huangzihao2025 @ 2023-07-10 08:59:09
@hehe625 谢谢
by Xdragon @ 2023-07-30 15:39:32
可以用滚动数组,是一维的