10723 - Cyborg Genes

#include <stdio.h>
#include <string.h>
#define LL long long
#define maxn 35
LL d[maxn][maxn][maxn],fd[maxn][maxn],ls1,ls2;
char s1[maxn],s2[maxn];
LL max(LL a,LL b)
{
	if(a>b) return a;
	else return b;
}
LL dp(int l1,int l2,int l3)
{
	LL &res=d[l1][l2][l3];
	if(res!=-1) return res;
	if(l1>l3||l2>l3) return res=0;
	if(l1==0&&l2==l3||l2==0&&l1==l3) return res=1;
	if(l1==0&&l2!=l3||l2==0&&l1!=l3) return res=0;
	if(s1[l1]==s2[l2]) res=dp(l1-1,l2-1,l3-1);
	else res=dp(l1-1,l2,l3-1)+dp(l1,l2-1,l3-1);
	return res;
}
int main()
{
	int t;
	scanf("%d",&t);
	getchar();
	for(int tt=1;tt<=t;tt++)
	{
		gets(s1+1);
		gets(s2+1);
		ls1=strlen(s1+1);
		ls2=strlen(s2+1);
		memset(fd,0,sizeof(fd));
		for(int i=1;i<=ls1;i++)
		{
			for(int j=1;j<=ls2;j++)
			{
				if(s1[i]==s2[j])
				fd[i][j]=fd[i-1][j-1]+1;
				else 
				fd[i][j]=max(max(fd[i-1][j-1],fd[i-1][j]),fd[i][j-1]);
			}
		}
		memset(d,-1,sizeof(d));
		printf("Case #%d: %lld %lld\n",tt,ls1+ls2-fd[ls1][ls2],dp(ls1,ls2,ls1+ls2-fd[ls1][ls2]));
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值