您的位置:首页 > 其它

PKU 2192 Zipper

2009-03-27 14:47 197 查看
PKU 2192 Zipper
http://acm.pku.edu.cn/JudgeOnline/problem?id=2192
晚上要讨论的题之一,先A一下
也是LCS的思想,关键是去找状态转移方程
AC CODE:
#include <iostream>
using namespace std;
#define maxlen 205
char a[maxlen]; //行
char b[maxlen]; //列
char str[maxlen*2];
bool recode[maxlen][maxlen] ;
// b a
int main()
{
int i,j,k,n,m,t,l;
while (scanf("%d",&t)!=EOF)
{
for (l=1;l<=t;l++)
{
memset(a+1,NULL,sizeof(a+1));
memset(b+1,NULL,sizeof(b+1));
memset(str+1,NULL,sizeof(str+1));
memset(recode,0,sizeof(recode));
scanf("%s",a+1);
scanf("%s",b+1);
scanf("%s",str+1);
int alen = strlen(a+1);
int blen = strlen(b+1);
recode[0][0] = 1;
for (i=0;i<=blen;i++) //列 b[]
{
for (j=0;j<=alen;j++) //行 a[]
{
if (i==0 && j==0)
{
continue;
}
if (recode[i-1][j] == 0 && recode[i][j-1] == 0 )
{
recode[i][j] = 0;
}
else if ((recode[i-1][j]&&str[i+j]==b[i]) || (recode[i][j-1]&&str[i+j]==a[j]))
{
recode[i][j] = 1;
}
}
}
//---------------------------------------------------
if (recode[blen][alen])
{
printf("Data set %d: yes/n",l);
}
else
{
printf("Data set %d: no/n",l);
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: