标签:
3 cat tree tcraete cat tree catrtee cat tree cttaree
Data set 1: yes Data set 2: yes Data set 3: no
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 char a[205],b[205],c[405]; 5 int l1,l2,l3; 6 bool flag; 7 int vis[205][205]; 8 void dfs(int x,int y,int z) 9 { 10 if(flag) 11 return; 12 if(z==l3) 13 { 14 flag=true; 15 return; 16 } 17 if(vis[x][y]==1) 18 return; 19 vis[x][y]=1; 20 if(a[x]==c[z]) 21 dfs(x+1,y,z+1); 22 if(b[y]==c[z]) 23 dfs(x,y+1,z+1); 24 } 25 int main() 26 { 27 int T,t; 28 cin>>T; 29 for(t=1;t<=T;t++) 30 { 31 cin>>a>>b>>c; 32 l1=strlen(a); 33 l2=strlen(b); 34 l3=strlen(c); 35 flag=false; 36 memset(vis,0,sizeof(vis));//防止超时 37 if(l1+l2==l3) 38 dfs(0,0,0); 39 printf("Data set %d: ",t); 40 if(flag)printf("yes\n"); 41 else printf("no\n"); 42 } 43 return 0; 44 }
标签:
原文地址:http://www.cnblogs.com/Annetree/p/5655317.html