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 ...
随机推荐
- jxls导出EXCEL模板
http://jxls.sourceforge.net/ InputStream templateInput = null; InputStream in = null; OutputStream o ...
- LeetCode OJ 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- iOS中的项目新特性页面的处理
一般项目中都会出现新特性页面,比如第一次使用应用的时候,或者在应用设置里查看新特性的时候会出现. 这里,选择新建一个专门处理项目新特性的控制器,来完成功能. 首先是 NewFeaturesViewCo ...
- IOS应用的国际化
IOS应用的国际化,主要分为3个部分: Info.plist 文件的国际化 .xib文件的国际化 .m文件的国际化 下面我就来一一说明. Info.plist 文件的国际化我们使用Xcode 4.5 ...
- hadoop 及hbase zookeeper 经常出现问题
往往是以下几个 1/ 各节点时间不统一(写shell文件统一时间) 2/配置文件 /etc/hosts文件中ip地址配置错误(更新ip) 3/断网后重启机器 ip地址被修改(更新配置文件中的ip)
- Hbase查看
Client HBase Client使用HBase的RPC机制与HMaster和HRegionServer进行通信,对于管理类操作,Client与HMaster进行RPC:对于数据读写类操作,Cli ...
- drawableLayout的使用(转载讲的比较清晰的文章)
创建drawbler的布局文件 初始化drawbler的列表 响应drawable列表点击事件 现在侧滑菜单使用很多,大都是通过SlidingMenu实现.现在也可以通过DrawerLayout 创建 ...
- mahout与nosql的两幅经典图形
- YII2 运行概述(Overview)
运行机制概述 每一次 Yii 应用开始处理 HTTP 请求时,它都会进行一个近似的流程. 用户提交指向 入口脚本 web/index.php 的请求. 入口脚本会加载 配置数组 并创建一个 应用 实例 ...
- python selenium基本
基本 from selenium import webdriver import re driver = webdriver.Firefox() driver.get('https://www.goo ...