hdu1501 Zipper
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
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
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
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
#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的更多相关文章
- 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 ...
- hdu1501 Zipper[简单DP]
目录 题目地址 题干 代码和解释 参考 题目地址 hdu1501 题干 代码和解释 最优子结构分析:设这三个字符串分别为a.b.c,如果a.b可以组成c,那么c的最后一个字母必定来自a或者b的最后一个 ...
- Combine String---hdu5727 &&& Zipper(LCS变形)
题目链接:http://poj.org/problem?id=2192 http://acm.split.hdu.edu.cn/showproblem.php?pid=5707 http://acm. ...
- POJ 2192 :Zipper(DP)
http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
- Zipper
Zipper Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU 1501 Zipper 动态规划经典
Zipper Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- HDU 1501 Zipper(DP,DFS)
意甲冠军 是否可以由串来推断a,b字符不改变其相对为了获取字符串的组合c 本题有两种解法 DP或者DFS 考虑DP 令d[i][j]表示是否能有a的前i个字符和b的前j个字符组合得到c的前i+j ...
- Zipper(poj2192)dfs+剪枝
Zipper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15277 Accepted: 5393 Descripti ...
- Haskell语言学习笔记(36)Data.List.Zipper
ListZipper 模块 $ cabal install ListZipper Installed ListZipper-1.2.0.2 Prelude> :m +Data.List.Zipp ...
随机推荐
- CevaEclipse - 编译器attribute扩展
1.函数与变量的 Section Attribute void foobar (void) __attribute__ ((section (".CSECT mmm"))); vo ...
- EnumPrinters用法
看API描述,不怎么理解,还是在网上找到用法,记载一下: 1: DWORD dwNeeded = 0, dwNum = 0; 2: EnumPrinters(PRINTER_ENUM_LOCAL, N ...
- URL匹配与req参数解析
通配URL*(可代表任何字符串) 例如: app.get('/test/*', function(req, res){ res.send(req.query.aa); }) '/test/*通配tes ...
- 1.0 Python 学习网站
w3cschool : http://www.runoob.com/python/python-tutorial.html cnblog Python 从入门到精通: http://www.cnbl ...
- sql 查询一段时间内某个时间点数据
SELECT CONVERT(VARCHAR(10), dtCreateTime, 120) AS dtStatisticsCreateDate, COUNT(1) AS nStatisticsC ...
- Apriori算法-位运算-C语言
原文地址:http://blog.csdn.net/liema2000/article/details/6118423 //////////////////////////////////////// ...
- Chapter 2 Open Book——5
I was relieved that I had the desk to myself, that Edward was absent. 我能一个人一张桌子很开心,就因为Edward 没来. I t ...
- how to use the curses library in unix?
In linux, you can use the ncurses library to use the terminal as a text buffer: move the cursor arou ...
- MySQL 出现 The table is full 的解决方法【转】
[MySQL FAQ]系列 — 你所不知的table is full那些事 时间 2014-08-21 12:18:56 MySQL中文网 原文 http://imysql.com/2014/08 ...
- 在Linux系统如何让程序开机时自动启动
在Linux系统如何让程序开机时自动启动 核心提示:系统的服务在开机时一般都可以自动启动,那在linux系统下如果想要程序在开机时自动启动怎么办?我们知道在 windows系统“开始”--& ...