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. cxLookupCombobox的多字段模糊匹配

    查了网上很多资料,懒人输入:通过程序使用过滤对话达到自己的目的: 用到cxFilter单元: cbb_DoctorOrder.Properties.View.DataController.Filter ...

  2. python mock模块使用(二)

    本篇继续介绍mock里面另一种实现方式,patch装饰器的使用,patch() 作为函数装饰器,为您创建模拟并将其传递到装饰函数 官方文档地址 patch简介 1.unittest.mock.patc ...

  3. 洛谷P1504 积木城堡

    题目描述 XC的儿子小XC最喜欢玩的游戏用积木垒漂亮的城堡.城堡是用一些立方体的积木垒成的,城堡的每一层是一块积木.小XC是一个比他爸爸XC还聪明的孩子,他发现垒城堡的时候,如果下面的积木比上面的积木 ...

  4. 【二分贪心+精度问题】F. Pie

    https://www.bnuoj.com/v3/contest_show.php?cid=9154#problem/F [题意] 给定n个已知半径的披萨,有m个人要分这n个披萨 要求每个人分到的面积 ...

  5. 爱在心中(codevs 2822)

    题目描述 Description “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸,世界就像迷宫,却又让我们此刻相逢Our Home.” 在爱的国度 ...

  6. 【zTree】zTree根据后台数据生成树并动态设置前面的节点复选框的选中状态

    0.页面中准备树的ul <ul id="treeDemo10" class="ztree" style="display: none;" ...

  7. msp430入门编程27

    msp430中C语言开发工具调试程序 msp430入门学习 msp430入门编程

  8. Windows Server 2003的一些优化设置 (转至网络)

    2003序列号:JCHKR-888KX-27HVK-DT88X-T767M1.禁用配置服务器向导: 禁止“配置你的服务器”(Manage Your Server)向导的出现:在控制面板(Control ...

  9. 2017CodeM初赛A场

    A.最长树链(loj6159) 分析: 对于每个质因数,取出所有是它倍数的点组成一个树,然后找最长路径 每个数操作次数是其质因数的个数 所以总的复杂度不超过O(nlogA) B.二分图染色(loj61 ...

  10. 使用微软的 ilasm 和 ildasm 对. net程序进行编译和反编译

    为了保证示例的完整性,请先准备好一个 c#写的 exe 程序,或者可以使用我提供的 exe 程序也可以(很简单,为了测试这里仅生成了一个带按钮的 winform,单击按钮提示弹窗) Test WinF ...