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

  1. 3
  2. cat tree tcraete
  3. cat tree catrtee
  4. cat tree cttaree

Sample Output

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

Source

Pacific Northwest 2004
女生赛类似的题
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. char a[],b[],c[];
  5. int l1,l2,l3;
  6. bool flag;
  7. int vis[][];
  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]==)
  18. return;
  19. vis[x][y]=;
  20. if(a[x]==c[z])
  21. dfs(x+,y,z+);
  22. if(b[y]==c[z])
  23. dfs(x,y+,z+);
  24. }
  25. int main()
  26. {
  27. int T,t;
  28. cin>>T;
  29. for(t=;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,,sizeof(vis));//防止超时
  37. if(l1+l2==l3)
  38. dfs(,,);
  39. printf("Data set %d: ",t);
  40. if(flag)printf("yes\n");
  41. else printf("no\n");
  42. }
  43. return ;
  44. }

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. 111python

    补充一句,为兼容平台文件地址可以这么写: file = os.path.join('dir', 'file_name')

  2. R6

    RC 的加强版是 R6 , R6 是一个扩展包,能够实现支持公共和私有字段与方法的更有效的引用类,还有一些其他强大的功能.运行以下代码安装这个包:install.packages("R6&q ...

  3. Codeforces 447C - DZY Loves Sequences

    447C - DZY Loves Sequences 思路:dp 代码: #include<bits/stdc++.h> using namespace std; #define ll l ...

  4. php时区设置 warning: strtotime(): It is not safe to rely on the system's timezone settings

    warning: strtotime(): It is not safe to rely on the system's timezone settings warning: strtotime(): ...

  5. [.NET开发] C# 如何创建Excel多级分组

    要设置显示或者隐藏分类数据下的详细信息,在便于数据查看.管理的同时也使文档更具美观性.那么,在C#中如何来创建Excel数据的多级分组显示呢?下面将进行详细阐述.方法中使用了免费版组件Free Spi ...

  6. RabbitMq windows 安装

    参考官方网址: http://www.rabbitmq.com/install-windows-manual.html http://www.rabbitmq.com/install-windows. ...

  7. android--------阿里 Sophix移动热修复

    移动热修复(Mobile Hotfix)是阿里云提供的全平台App热修复服务方案.产品基于阿里巴巴首创hotpatch技术,提供最细粒度热修复能力,让您无需等待实时修复应用线上问题. 移动热修复提供的 ...

  8. 『PyTorch』第五弹_深入理解Tensor对象_上:初始化以及尺寸调整

    一.创建Tensor 特殊方法: t.arange(1,6,2)t.linspace(1,10,3)t.randn(2,3) # 标准分布,*size t.randperm(5) # 随机排序,从0到 ...

  9. python-day71--django多表操作

    表关系: 1 一对多 2 多对多 3 一对一 添加记录: 一对多:书与出版社 #创建一对多: publish=models.ForeignKey("Publish") 注意:pub ...

  10. ScoketTimeout Exception浅析

    以前都是用WebService的方式调用服务方的服务,此次直接调用别人的http服务. 使用的客户端是org.apache.http.client.HttpClient. 用的httpclient-4 ...