#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int f[2][5005];
int g[2][5005];
char a[5005],b[5005];
int main()
{
scanf("%s%s",a+1,b+1);
int m=strlen(a+1)-1;
int n=strlen(b+1)-1;
a[m+1]='\0';
b[n+1]='\0';
int now=1;
int pre=0;
g[0][0]=1;
g[1][0]=1;
for(int k=1;k<=n;k++)
g[0][k]=1;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
g[now][j]=0;
if(a[i]==b[j])f[now][j]=f[pre][j-1]+1;
else f[now][j]=max(f[pre][j],f[now][j-1]);
if(a[i]==b[j])
g[now][j]+=g[pre][j-1]%100000000;\\本来这里else现在举了个反例BA,AA f[pre][j-1]=f[pre][j]=0;
if(f[now][j]==f[pre][j])
g[now][j]+=g[pre][j]%100000000;
if(f[now][j]==f[now][j-1])
g[now][j]+=g[now][j-1]%100000000;
if(f[now][j]==f[pre][j-1])
g[now][j]-=g[pre][j-1]%100000000;
}
now=pre;
pre=1-pre;
}
cout<<f[pre][n]<<endl;
cout<<g[pre][n]%100000000;
return 0;
}
P2516 [HAOI2010]最长公共子序列
最新推荐文章于 2025-05-20 22:23:34 发布

165

被折叠的 条评论
为什么被折叠?



