Problem Descriptiongiven Three strings, you is to determine whether the third string can is formed by combining the Chara Cters in the first and the strings. The first and the strings can is mixed arbitrarily, but each must stay on its original order.
For example, consider forming "tcraete" from "Cat" and "tree":
String A:cat
String B:tree
String C:tcraete
As can see, we can form the third string by alternating characters from the strings. As a second example, consider forming "catrtee" from "Cat" and "tree":
String A:cat
String B:tree
String C:catrtee
Finally, notice that it's impossible to form "cttaree" from "Cat" and "tree". Inputthe first line of input contains a single positive integer from 1 through 1000. It represents the number of data sets to follow. The processing for each data set is identical. The data sets appear on the following lines, and one data set per line.
For each data set, the line of input consists of three strings, separated by a single space. All strings is composed of upper and lower case letters only. The length of the third string is always the sum of the lengths of the first and the strings. The first and strings would have lengths between 1 and characters, inclusive.
Outputfor each data set, print:
Data Set N:yes
If the third string can be formed from the first, or
Data Set N:no
If it cannot. Of course n should is replaced by the data set number. See the sample output below for an example. Sample Input
3cat Tree tcraetecat Tree catrteecat tree Cttaree
Sample Output
Data set 1:yesdata set 2:yesdata set 3:no
Sourcepacific Northwest 2004
1#include <iostream>2#include <cstring>3 using namespacestd;4 Chara[205],b[205],c[405];5 intL1,l2,l3;6 BOOLFlag;7 intvis[205][205];8 voidDfsintXintYintz)9 {Ten if(flag) One return; A if(z==L3) - { -flag=true; the return; - } - if(vis[x][y]==1) - return; +vis[x][y]=1; - if(a[x]==C[z]) +DFS (x+1, y,z+1); A if(b[y]==C[z]) atDFS (x,y+1, z+1); - } - intMain () - { - intt,t; -Cin>>T; in for(t=1; t<=t;t++) - { toCin>>a>>b>>C; +l1=strlen (a); -L2=strlen (b); thel3=strlen (c); *flag=false; $memset (Vis,0,sizeof(VIS));//Prevent TimeoutsPanax Notoginseng if(l1+l2==L3) -Dfs0,0,0); theprintf"Data Set%d:", T); + if(flag) printf ("yes\n"); A Elseprintf"no\n"); the } + return 0; -}
HDU 1501 Zipper