2896: J--Zipper

时间限制: 1 Sec  内存限制: 128 MB

提交: 29  解决: 15

题目描述

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".

输入

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.

输出

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.

样例输入

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

样例输出

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

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

  1. #include<stdio.h>
  2. #include<string.h>
  3. #define MAX 201
  4. int opt[MAX][MAX];
  5. int main()
  6. {
  7. int n;
  8. int cnt=0;
  9. char str1[MAX],str2[MAX],str3[MAX*2];
  10. int len_str1,len_str2,len_str3;
  11. int i,j;
  12. scanf("%d",&n);
  13. while(n--)
  14. {
  15. cnt++;
  16. scanf("%s %s %s",str1,str2,str3);
  17. len_str1=strlen(str1);
  18. len_str2=strlen(str2);
  19. len_str3=strlen(str3);
  20. if(len_str1+len_str2!=len_str3)
  21. {
  22. printf("Data set %d: no\n",cnt);
  23. continue;
  24. }
  25. memset(opt,0,sizeof(opt));
  26. opt[0][0]=1;
  27. for(i=1; i<=len_str1; i++)
  28. {
  29. if(opt[i-1][0]==1&&str1[i-1]==str3[i-1]) opt[i][0]=1;
  30. else break;
  31. }
  32. for(j=1; j<=len_str2; j++)
  33. {
  34. if(opt[0][j-1]==1&&str2[j-1]==str3[j-1]) opt[0][j]=1;
  35. else break;
  36. }
  37. for(i=1; i<=len_str1; i++)
  38. {
  39. for(j=1; j<=len_str2; j++)
  40. {
  41. if((opt[i][j-1]==1&&str2[j-1]==str3[i+j-1])||(opt[i-1][j]==1&&str1[i-1]==str3[i+j-1]))
  42. opt[i][j]=1;
  43. }
  44. }
  45. if(opt[len_str1][len_str2]) printf("Data set %d: yes\n",cnt);
  46. else printf("Data set %d: no\n",cnt);
  47. }
  48. return 0;
  49. }

YTU 2896: J--Zipper的更多相关文章

  1. YTU 3026: 中序线索化二叉树

    原文链接:https://www.dreamwings.cn/ytu3026/2896.html 3026: 中序线索化二叉树 时间限制: 1 Sec  内存限制: 128 MB 提交: 9  解决: ...

  2. HDU 2896 (AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2896 题目大意:多个模式串.多个匹配串.其中串的字符范围是(0~127).问匹配串中含有哪几个模式串 ...

  3. POJ 2192 :Zipper(DP)

    http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

  4. Zipper

      Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. hdoj 2896 病毒侵袭(AC自动机)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2896 思路分析:题目为模式匹配问题,对于一个给定的字符串,判断能匹配多少个模式:该问题需要静态建树,另 ...

  6. HDU 1501 Zipper 动态规划经典

    Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  7. HDU 1501 Zipper(DP,DFS)

    意甲冠军  是否可以由串来推断a,b字符不改变其相对为了获取字符串的组合c 本题有两种解法  DP或者DFS 考虑DP  令d[i][j]表示是否能有a的前i个字符和b的前j个字符组合得到c的前i+j ...

  8. hdu1501 Zipper

    Zipper Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  9. Zipper(poj2192)dfs+剪枝

    Zipper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15277   Accepted: 5393 Descripti ...

随机推荐

  1. mysql查最大字符串

    select MAX(comp_code+0) from t_base_company 字符串 +0 把字符串转成数字

  2. Coloring Brackets (区间DP)

    Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a soluti ...

  3. 【并查集】F.find the most comfortable road

    https://www.bnuoj.com/v3/contest_show.php?cid=9146#problem/F [题意] 给定n个城市和m条带权边,q次查询,问某两个城市之间的所有路径中最大 ...

  4. HTTP错误:java.lang.IllegalArgumentException: Illegal character in scheme at index 0: http://xxxxxx

    读取T卡文件里的域名,HTTP请求出现如下错误 java.lang.IllegalArgumentException: Illegal character in scheme at index 0: ...

  5. FusionCharts for Flex 如何更改图表数据

    FusionCharts allows to change chart data and re-render the chart, after it has loaded on the user’s ...

  6. Event Logging 技术简介

    https://blog.csdn.net/xiliang_pan/article/details/41805023

  7. http_load分析(转)

    http://www.cnblogs.com/xuning/p/3954057.html 一.前言 http_load是一款测试web服务器性能的开源工具,从下面的网址可以下载到最新版本的http_l ...

  8. [Bzoj5177][Jsoi2013]贪心的导游(主席树)

    5177: [Jsoi2013]贪心的导游 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 32  Solved: 15[Submit][Status] ...

  9. Spring中使用构造函数实现Beans自动装配

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/beans-auto-wiring/spring-autowiring-by-Constructor ...

  10. ArcEngine读取ShapeFile时,出现乱码的解决方案

    ArcEngine读取ShapeFile时,如果用LicenseControl的话,字段中含有汉字时可以正常使用,当使用LicenseInitializer进行初始化时,读取含有汉字的字段时,就会出现 ...