hdu 1501 Zipper dfs
题目链接: HDU - 1501
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".
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.
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.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+; int flag;
char s[maxn],s2[maxn],s3[maxn+maxn];
int vis[maxn][maxn];
int cnt,cnt2,cnt3,len,len2,len3; void dfs(int sum,int x,int y)
{
if (sum >= len3) {flag=;return ;}
if (s[x]!=s3[sum] && s2[y]!=s3[sum])
return ;
if (vis[x][y]) return ;
vis[x][y]=;
if (s[x]==s3[sum]) dfs(sum+,x+,y);
if (s2[y]==s3[sum]) dfs(sum+,x,y+);
return ;
} int main()
{
int t,ncase=;
while (scanf("%d",&t)!=EOF)
{
while (t--)
{
scanf("%s%s%s",s,s2,s3);
len=strlen(s);
len2=strlen(s2);
len3=strlen(s3);
flag=;
memset(vis,,sizeof(vis));
if (s3[len3-]==s[len-]||s3[len3-]==s2[len2-])
dfs(,,);
if (flag) printf("Data set %d: yes\n",ncase++);
else printf("Data set %d: no\n",ncase++);
}
}
return ;
}
hdu 1501 Zipper dfs的更多相关文章
- (step4.3.5)hdu 1501(Zipper——DFS)
题目大意:个字符串.此题是个非常经典的dfs题. 解题思路:DFS 代码如下:有详细的注释 /* * 1501_2.cpp * * Created on: 2013年8月17日 * Author: A ...
- HDU 1501 Zipper 【DFS+剪枝】
HDU 1501 Zipper [DFS+剪枝] Problem Description Given three strings, you are to determine whether the t ...
- HDU 1501 Zipper(DP,DFS)
意甲冠军 是否可以由串来推断a,b字符不改变其相对为了获取字符串的组合c 本题有两种解法 DP或者DFS 考虑DP 令d[i][j]表示是否能有a的前i个字符和b的前j个字符组合得到c的前i+j ...
- HDU 1501 Zipper(DFS)
Problem Description Given three strings, you are to determine whether the third string can be formed ...
- hdu 1501 Zipper
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1501 思路:题目要求第三个串由前两个组成,且顺序不能够打乱,搜索大法好 #include<cstdi ...
- HDU 1501 Zipper 动态规划经典
Zipper Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- HDU 1501 Zipper 字符串
题目大意:输入有一个T,表示有T组测试数据,然后输入三个字符串,问第三个字符串能否由第一个和第二个字符串拼接而来,拼接的规则是第一个和第二个字符串在新的字符串中的前后的相对的顺序不能改变,问第三个字符 ...
- hdu 1501 Zipper(DP)
题意: 给三个字符串str1.str2.str3 问str1和str2能否拼接成str3.(拼接的意思可以互相穿插) 能输出YES否则输出NO. 思路: 如果str3是由str1和str2拼接而成,s ...
- HDOJ 1501 Zipper 【DP】【DFS+剪枝】
HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
随机推荐
- 孤荷凌寒自学python第五十三天使用python写入和修改Firebase数据库中记录
孤荷凌寒自学python第五十三天使用python写入和修改Firebase数据库中记录 (完整学习过程屏幕记录视频地址在文末) 今天继续研究Firebase数据库,利用google免费提供的这个数 ...
- 孤荷凌寒自学python第五十二天初次尝试使用python读取Firebase数据库中记录
孤荷凌寒自学python第五十二天初次尝试使用python读取Firebase数据库中记录 (完整学习过程屏幕记录视频地址在文末) 今天继续研究Firebase数据库,利用google免费提供的这个数 ...
- Bat 修改 xml 文件标签值
xml 文件如下: <ConfigurationData> <ReportsFolder>\Reports</ReportsFolder> <Helpfold ...
- KMS激活windows
slmgr /skms 106.0.6.209 slmgr /ato .查看当前系统是否永久激活,命令的作用是查看当前许可证状态的截止日期 slmgr.vbs -xpr 查看Windows正式版产品密 ...
- CodeForces-1061B Views Matter
题目链接 https://vjudge.net/problem/CodeForces-1061B 题面 Description You came to the exhibition and one e ...
- 分享下自己一直用的.NET SQLSERVER 封装类下自己写的DataHelper 操作类
一,概述: 这个DataHelper 类是基于我上个博客里发的SQLDataAccess 这个类做的一个简单的封装,为了结合自己的实体类和数据操作而产生的. 这里面用了 属性类,反射.还有 数据类型 ...
- BZOJ5157 [Tjoi2014]上升子序列 【树状数组】
题目链接 BZOJ5157 题解 我们只需计算每个位置为开头产生的贡献大小,就相当于之后每个大于当前位置的位置产生的贡献 + 1之和 离散化后用树状数组维护即可 要注意去重,后面计算的包含之前的,记录 ...
- mysql插入表情问题
http://blog.csdn.net/wxc20062006/article/details/19547179http://blog.csdn.net/xb12369/article/detail ...
- Velocity模版使用
<!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity --> <dependency> &l ...
- 转:android listview局部刷新和模拟应用下载
在 android开发中,listview是比较常用的一个组件,在listview的数据需要更新的时候,一般会用 notifyDataSetChanged()这个函数,但是它会更新listview中所 ...