hdu 1501 基本搜索深搜

#include<stdio.h>
#include<string.h>
char s1[300],s2[300],s[500];
int len1,len2,len3,flag,used[300][300];
void dfs(int a,int b,int c) {
 if(flag)
  return ;
 if(c==len3) {
  flag=1;
  return ;
 }
 if(used[a][b])
  return ;
 used[a][b]=1;
     if(s1[a]==s[c])
   dfs(a+1,b,c+1);
  if(s2[b]==s[c])
   dfs(a,b+1,c+1);
}
int main() {
 int t,co=0;
 scanf("%d",&t);
 while(t--) {
  scanf("%s%s%s",s1,s2,s);
  len1=strlen(s1);
  len2=strlen(s2);
  len3=strlen(s);
  flag=0; 
  memset(used,0,sizeof(used));
  dfs(0,0,0);
  if(flag)
        printf("Data set %d: yes ",++co);
  else
    printf("Data set %d: no ",++co);
 }
 return 0;
}

原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410991.html