Zipper

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 59   Accepted Submission(s) : 26

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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<cstdio>
#include<cstring>
using namespace std;
int t,flag,l1,l2,l3;
char ch1[],ch2[],ch3[];
int f[][];
void dfs(int i,int j,int k)
{
if (k==l3)
{
flag=;
return;
}
if (f[i][j]) return;
f[i][j]=;
if (i<l1)
if (ch3[k]==ch1[i]) dfs(i+,j,k+);
if (flag) return;
if (j<l2)
if (ch3[k]==ch2[j]) dfs(i,j+,k+);
if (flag) return;
}
int main()
{
scanf("%d",&t);
for(int tt=;tt<=t;tt++)
{
scanf("%s%s%s",&ch1,&ch2,&ch3);
l1=strlen(ch1);
l2=strlen(ch2);
l3=strlen(ch3);
printf("Data set %d: ",tt);
flag=;
memset(f,,sizeof(f));
dfs(,,);
if (flag) printf("yes\n");
else printf("no\n");
}
return ;
}

hdu1501 Zipper的更多相关文章

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

  2. hdu1501 Zipper[简单DP]

    目录 题目地址 题干 代码和解释 参考 题目地址 hdu1501 题干 代码和解释 最优子结构分析:设这三个字符串分别为a.b.c,如果a.b可以组成c,那么c的最后一个字母必定来自a或者b的最后一个 ...

  3. Combine String---hdu5727 &&& Zipper(LCS变形)

    题目链接:http://poj.org/problem?id=2192 http://acm.split.hdu.edu.cn/showproblem.php?pid=5707 http://acm. ...

  4. POJ 2192 :Zipper(DP)

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

  5. Zipper

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

  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. Zipper(poj2192)dfs+剪枝

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

  9. Haskell语言学习笔记(36)Data.List.Zipper

    ListZipper 模块 $ cabal install ListZipper Installed ListZipper-1.2.0.2 Prelude> :m +Data.List.Zipp ...

随机推荐

  1. Xcode中AutoLayOut的简单使用

    做了一段界面最头疼的就是适配的问题了,使用AutoLayOut做适配是一个不错的选择, 自己做的一个小例子,具体如下: 一.在新建的xib文件中勾选上 autoLayout,默认是勾选上的 二.在xi ...

  2. ios 中Category类别(扩展类)小结

    类别 类别是一种为现有的类添加新方法的方式.利用Objective-C的动态运行时(runtime)分配机制,可以为现有的类添加新方法,这种为现有的类添加新方法的方式称为类别catagory,他可以为 ...

  3. tomcat配置多个虚拟主机

    先修改默认端口(8080),http的默认端口是80,我们将8080改成80,这样域名就不用带上端口了 修改conf文件夹下的server.xml文件 添加多个主机(以下三个主机对应三个域名,三个域名 ...

  4. SpringMVC的视图解析器

    ViewResolver和View介绍 SpringMVC用于处理视图最重要的两个接口是ViewResolver和View.ViewResolver的主要作用是把一个逻辑上的视图名称解析为一个真正的视 ...

  5. 接入支付宝出现交易订单处理失败,请稍后再试(ALI64)的错误【转】

    接入第三方平台的时候,有时虽然按照文档来做,但是总是还会有各种各样的问题. 上次在接入支付宝的时候就碰到了交易订单处理失败,请稍后再试(ALI64)这样的错误,后来经过排查和总结,一般来讲这种问题都是 ...

  6. STM32F407的串口采用DMA收发数据

    源:STM32F407的串口采用DMA收发数据

  7. CentOS的KVM实践(虚拟机创建、网桥配置、Spice)

    最近公司准备上一套基于openstack的虚拟桌面系统,作为该项目的负责人,觉得有必要自己实践一下,该系统的搭建.最基础的就是需要了解基于linux的kvm的实践. 一.基础软件包准备 系统是采用px ...

  8. java代理的深入浅出(一)-Proxy

    java代理的深入浅出(一)-Proxy 1.什么是代理 代理模式是常用的java设计模式,他的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事 ...

  9. linux脚本Shell之awk详解

    一.基本介绍1.awk: awk是一个强大的文本分析工具,在对文本文件的处理以及生成报表,awk是无可替代的.awk认为文本文件都是结构化的,它将每一个输入行定义为一个记录,行中的每个字符串定义为一个 ...

  10. WebViewJavascriptBridge详细使用

    前言 WebViewJavascriptBridge是支持到iOS6之前的版本的,用于支持native的iOS与javascript交互.如果需要支持到iOS6之前的app,使用它是很不错的.本篇讲讲 ...