Problem Description

Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order.

For example, consider forming "tcraete" from "cat" and "tree":

String A: cat
String B: tree
String C: tcraete

As you can see, we can form the third string by alternating characters from the two 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 is impossible to form "cttaree" from "cat" and "tree".

Input

The 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, one data set per line.

For each data set, the line of input consists of three strings, separated by a single space. All strings are composed of upper and lower case letters only. The length of the third string is always the sum of the lengths of the first two strings. The first two strings will have lengths between 1 and 200 characters, inclusive.

Output

For each data set, print:

Data set n: yes

if the third string can be formed from the first two, or

Data set n: no

if it cannot. Of course n should be replaced by the data set number. See the sample output below for an example.

Sample Input

3
cat tree tcraete
cat tree catrtee
cat tree cttaree

Sample Output

Data set 1: yes
Data set 2: yes
Data set 3: no

Source

Pacific Northwest 2004
女生赛类似的题
 #include<iostream>
#include<cstring>
using namespace std;
char a[],b[],c[];
int l1,l2,l3;
bool flag;
int vis[][];
void dfs(int x,int y,int z)
{
if(flag)
return;
if(z==l3)
{
flag=true;
return;
}
if(vis[x][y]==)
return;
vis[x][y]=;
if(a[x]==c[z])
dfs(x+,y,z+);
if(b[y]==c[z])
dfs(x,y+,z+);
}
int main()
{
int T,t;
cin>>T;
for(t=;t<=T;t++)
{
cin>>a>>b>>c;
l1=strlen(a);
l2=strlen(b);
l3=strlen(c);
flag=false;
memset(vis,,sizeof(vis));//防止超时
if(l1+l2==l3)
dfs(,,);
printf("Data set %d: ",t);
if(flag)printf("yes\n");
else printf("no\n");
}
return ;
}

HDU 1501 Zipper(DFS)的更多相关文章

  1. hdu 1501 Zipper(DP)

    题意: 给三个字符串str1.str2.str3 问str1和str2能否拼接成str3.(拼接的意思可以互相穿插) 能输出YES否则输出NO. 思路: 如果str3是由str1和str2拼接而成,s ...

  2. HDU 1501 Zipper 【DFS+剪枝】

    HDU 1501 Zipper [DFS+剪枝] Problem Description Given three strings, you are to determine whether the t ...

  3. HDU 5965 扫雷(dfs)题解

    题意:给你一个3*n的格子,中间那行表明的是周围8格(当然左右都没有)的炸弹数量,上下两行都可以放炸弹,问你有几种可能,对mod取模 思路:显然(不),当i - 1和i - 2确定时,那么i的个数一定 ...

  4. HDU 1518 Square(DFS)

    Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end ...

  5. HDU 1015 Safecracker (DFS)

    题意:给一个数字n(n<=12000000)和一个字符串s(s<=17),字符串的全是有大写字母组成,字母的大小按照字母表的顺序,比如(A=1,B=2,......Z=26),从该字符串中 ...

  6. Hdu 1175 连连看(DFS)

    Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1175 因为题目只问能不能搜到,没问最少要几个弯才能搜到,所以我采取了DFS. 因为与Hdu ...

  7. HDU1501 Zipper(DFS) 2016-07-24 15:04 65人阅读 评论(0) 收藏

    Zipper Problem Description Given three strings, you are to determine whether the third string can be ...

  8. 【OpenJ_Bailian - 2192】Zipper(dfs)

    Zipper Descriptions: Given three strings, you are to determine whether the third string can be forme ...

  9. hdu 2821 Pusher (dfs)

    把这个写出来是不是就意味着把   http://www.hacker.org/push  这个游戏打爆了? ~啊哈哈哈 其实只要找到一个就可以退出了  所以效率也不算很低的  可以直接DFS呀呀呀呀 ...

随机推荐

  1. hdu 5668 Circle 中国剩余定理

    Circle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem D ...

  2. Linux Shell学习笔记(一)

    Shell,见名知意,就是一个作为用户与Linux OS间接口的程序,允许用户向OS输入需要执行的命令.Shell众多,这里只介绍Bash. 0)实验的Shell版本 显示shell版本: /bin/ ...

  3. python 插入查找

    def interpolation_search(data,val): low= high=len(data)- print('查找过程中......') : mid=low+int((val-dat ...

  4. Python的函数参数传递

    a = 1 def fun(a): a = 2 fun(a) print a # 1 a = [] def fun(a): a.append(1) fun(a) print a # [1]

  5. c++ 判断容器A是否是容器B的子集,如果是,返回true(includes)

    #include <iostream> // cout #include <algorithm> // includes, sort using namespace std; ...

  6. editplus5激活码

    editplus5激活码 name: Vovan code: 3AG46-JJ48E-CEACC-8E6EW-ECUAW 转自:https://blog.csdn.net/webfront/artic ...

  7. signal_windows

    1.Qt532(vs2010 opengl) // ZC: windows signal: // http://blog.csdn.net/mergerly/article/details/79521 ...

  8. Confluence 6 配置用户目录

    一个用户目录是你存储你的用户和用户组信息的地方.用户信息包括有用户的全名,用户名,密码和电子邮件地址以及其他的一些个人信息. 用户组包括有用户组名字,属于这个用户组的用户和有可能属于这个用户组的另一个 ...

  9. Idea改项目名

    1.点开.idea文件夹,找到 modules.xml,更改里面的项目名 2.根目录下对应的.iml文件 3.右击 pom.xml 文件,选择最下面的 “ Add as maven build fil ...

  10. 使用与不使用@RequestBody注解的区别

    1. 如果使用@RequestBody接受页面参数: public Map<String,Object> insertBudget(@ApiParam(required = true,na ...