R浩轩泽Anmicius @ 2019-09-14 11:12:28
呈上我的代码(dp会爆空间啊愁)
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100001
int n,i,j,dp[10001][10001];
short a[N],b[N];
void lcs(int n)
{
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1;
else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
int main()
{
memset(dp,0,sizeof(dp));
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%sd",&a[i]);
for(i=0;i<n;i++)
scanf("%sd",&b[i]);
lcs(n);
printf("%d\n",dp[n][n]);
return 0;
}
“我秃了”
“但我没有变强”
by 142857cs @ 2019-09-14 11:14:16
@Jessie12138 dp过不了,要转LIS做
by 142857cs @ 2019-09-14 11:14:50
话说你最后那句话是什么梗啊
by 斗神_君莫笑 @ 2019-09-14 11:21:06
@Jessie12138 那是排列,有特殊性质
by R浩轩泽Anmicius @ 2019-09-14 11:23:06
蛤......是时候翻题解了