您的位置:首页 > 其它

hdu(1501) Zipper

2013-08-27 18:27 411 查看
这个搜索很好想,主要是标记问题,不标记会超时;

用map标记找过的字符;

#include"stdio.h"

#include"string.h"

char a[606],b[606],c[606];

int len3,flag,map[606][606];

void bfs(int x,int y,int z)

{

if(z==len3)

{

flag=1;

return ;

}

if(map[x][y])

return ;

if(flag)

return ;

map[x][y]=1;

if(a[x]==c[z])

bfs(x+1,y,z+1);

if(b[y]==c[z])

bfs(x,y+1,z+1);

}

int main()

{

int k,r=1,len1,len2;

scanf("%d",&k);

while(k--)

{

scanf("%s%s%s",a,b,c);

printf("Data set %d: ",r++);

len1=strlen(a);len2=strlen(b);

len3=strlen(c);

memset(map,0,sizeof(map));

if(len1+len2!=len3)

{

printf("no\n");

continue;

}

flag=0;

bfs(0,0,0);

if(flag)

printf("yes\n");

else

printf("no\n");

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: