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.

样例输入

3
cat tree tcraete
cat tree catrtee
cat tree cttaree

样例输出

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

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

#include<stdio.h>
#include<string.h>
#define MAX 201
int opt[MAX][MAX];
int main()
{
int n;
int cnt=0;
char str1[MAX],str2[MAX],str3[MAX*2];
int len_str1,len_str2,len_str3;
int i,j;
scanf("%d",&n);
while(n--)
{
cnt++;
scanf("%s %s %s",str1,str2,str3);
len_str1=strlen(str1);
len_str2=strlen(str2);
len_str3=strlen(str3);
if(len_str1+len_str2!=len_str3)
{
printf("Data set %d: no\n",cnt);
continue;
}
memset(opt,0,sizeof(opt));
opt[0][0]=1;
for(i=1; i<=len_str1; i++)
{
if(opt[i-1][0]==1&&str1[i-1]==str3[i-1]) opt[i][0]=1;
else break;
}
for(j=1; j<=len_str2; j++)
{
if(opt[0][j-1]==1&&str2[j-1]==str3[j-1]) opt[0][j]=1;
else break;
}
for(i=1; i<=len_str1; i++)
{
for(j=1; j<=len_str2; j++)
{
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]))
opt[i][j]=1;
}
}
if(opt[len_str1][len_str2]) printf("Data set %d: yes\n",cnt);
else printf("Data set %d: no\n",cnt);
}
return 0;
}

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. ExtJs 滚动条问题

    bodyStyle :'overflow-x:visible;overflow-y:scroll', //隐藏水平滚动条 通过这个方法可以显示或隐藏滚动条 var form = new Ext.for ...

  2. &quot;转成"

    在java中这样转 StringEscapeUtils.unescapeHtml(soapResponseData); 在js中这样转 str.replace(""",& ...

  3. spring boot学习01【搭建环境、创建第一个spring boot项目】

    1.给eclipse安装spring boot插件 Eclipse中安装Spring工具套件(STS): Help -> Eclipse Marketplace... 在Search标签或者Po ...

  4. ERP类系统设计学习

    文章:分布式.服务化的ERP系统架构设计 文章的方法是对系统进行拆分,拆分成多个子系统.

  5. POJ2926-Requirements,曼哈顿距离。去掉绝对值符号暴力枚举所有情况,神薙!

                                                         Requirements 好吧,这题我实在想不到什么优化的方法,看了看讨论区,顺便膜拜了一下大 ...

  6. HDU-1210Eddy's 洗牌问题

    Eddy's 洗牌问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Prob ...

  7. smartctl---查看硬件接口

    1.查看磁盘信息: #smartctl -i /dev/sda smartctl 5.42 2011-10-20 r3458 [x86_64-linux-2.6.18-308.16.1.el5] (l ...

  8. BZOJ2662[BeiJing wc2012]冻结【SPFA】

    “我要成为魔法少女!” “那么,以灵魂为代价,你希望得到什么?” “我要将有关魔法和奇迹的一切,封印于卡片之中„„”        在这个愿望被实现以后的世界里,人们享受着魔法卡片(SpellCard ...

  9. hdu1160简单dp最长下降子序列

    /* 简单dp,要记录顺序 解:先排序,然后是一个最长下降子序列 ,中间需记录顺序 dp[i]=Max(dp[i],dp[j]+1); */ #include<stdio.h> #incl ...

  10. Foundation框架的一些实用方法:替换字符串,去空格,反转

    //定义一个可变字符串, Format后面可以跟字符串类型,也可以传入C语言的字符串数组 NSMutableString *str = [NSMutableString stringWithForma ...