【DFS(记忆化)】hdu 1501 Zipper

51 篇文章 0 订阅

http://acm.hdu.edu.cn/showproblem.php?pid=1501

分析:记忆化搜索

注释掉后反而更快了哭


#include <iostream>
#include <cstdio>
//#include <queue>
#include <cstring>
#include <string>
using namespace std;

const int NM=205;
char s1[NM],s2[NM],str[NM<<1];
int vis[NM][NM],len1,len2,len;
bool flag;

void DFS(int t1,int t2,int t)
{
	if(flag) return;
	if(t==len){
		flag=true;return;
	}
	if(vis[t1][t2]) return;
	vis[t1][t2]=1;
	/*if(str[t]!=s1[t1] && str[t]!=s2[t2]){
		return ;
	}
	if(t1==len1){
		if(strcmp(&s2[t2],&str[t])==0) flag=true;
		return;
	}
	if(t2==len2){
		if(strcmp(&s1[t1],&str[t])==0) flag=true;
		return;
	}*/
	
	if(str[t]==s1[t1]) DFS(t1+1,t2,t+1);

	if(str[t]==s2[t2]) DFS(t1,t2+1,t+1);	
}

int main()
{
	int T,i;
	scanf("%d",&T);
	i=1;
	while(T--){
		scanf("%s%s%s",s1,s2,str);
		len1=strlen(s1);
		len2=strlen(s2);
		len=strlen(str);
		flag=false;
		memset(vis,0,sizeof(vis));
		DFS(0,0,0);
		if(flag) printf("Data set %d: yes\n",i++);
		else printf("Data set %d: no\n",i++);
	}
	return 0;
}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值