nj_peak @ 2023-10-10 13:39:20
50pts 求助!!!
#include<bits/stdc++.h>
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
using namespace std;
char buf[1<<20],*p1,*p2;
inline int read()
{
int re=0,ad=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
ad=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
re=(re<<3)+(re<<1)+(c^48);
c=getchar();
}
return re*ad;
}
inline void write(int wr)
{
if(wr<0)
putchar('-'),wr=-wr;
if(wr>9)
write(wr/10);
putchar(wr%10+'0');
return;
}
int dp[5555][5555],a[114514],b[114514];
int n;
int main()
{
n=read();
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++)
{
dp[i][j]=max(dp[i-1][j],dp[i][j]);
if(a[i]==b[j])
dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
}
write(dp[n][n]);
return 0;
}
by zhzkiller @ 2023-10-10 13:41:36
你数组开小了,dp也要开,而且这种做法不是会寄吗
by zhzkiller @ 2023-10-10 13:42:10
我到现在也就 50 分 @nj_peak
by nj_peak @ 2023-10-10 13:44:43
开大会MLE @zhzkiller
by zhzkiller @ 2023-10-10 13:49:58
@nj_peak 这题就是卡你n方做法,换算法吧
by nj_peak @ 2023-10-11 07:06:06
ok @zhzkiller