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 input3cat Tree tcraetecat tree catrteecat tree Cttaree
Sample Outputdata Set 1:yesdata set 2:yesdata set 3:no first say about string matching the basic idea of finding a B two digits in sequence and the comparison in C if the match is appropriate, A/b and C coordinates move forward one The end of the search is the end of the string ' \ ' Here is a DFS parameter with three coordinates for a B C three array (when a bit of a B and C are the same time the branch is also due to the presence of the branch so the tag array can be used to prune) due to the arrival of the coordinates I J (because the length of the C array And so k is not necessary as a two-dimensional array of parameters to be able to take care of the situation there are many kinds of things our goal is to match the characters when the coordinates are I j the rest of the characters are the same, so no matter how the match to I J case is the same, in order to avoid the timeout here can be used to memorize a tag Search and paste the code #include<stdio.h>
#include <iostream>
#include <string.h>
using namespace Std;
String a,b,c;
int Vis[501][500],flag;
void Dfs (int i,int j,int k)
{
if (Vis[i][j]) return;//the number of marked times directly ignores vis[i][j]=1; Mark
if (c[k]== ')
{
flag=1;
Return
}
if (A[i]==c[k]&&b[j]==c[k])
{
DFS (I+1,J,K+1);
DFS (I,J+1,K+1);
}else if (A[i]==c[k]&&b[j]!=c[k])
{
DFS (I+1,J,K+1);
}else if (A[i]!=c[k]&&b[j]==c[k])
{
DFS (I,J+1,K+1);
}
}
int main ()
{
int n,i;
scanf ("%d", &n);
for (i=1;i<=n;i++)
{
cin>>a>>b>>c;
flag=0;
memset (vis,0,sizeof (VIS));
DFS (0,0,0);
printf ("Data Set%d:", i);
if (flag==1) cout<< "yes" <<endl;
else cout<< "No" <<endl;
}
return 0;
}
hdu1501 Memory Search ...