hdu1501 记忆化搜索。。。
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".
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.
cat tree tcraete
cat tree catrtee
cat tree cttaree
Data set 2: yes
Data set 3: no
#include<iostream>
#include<string.h>
using namespace std;
string a,b,c;
int vis[501][500],flag;
void dfs(int i,int j,int k)
{
if(vis[i][j]) return;// 对标记过的次数直接忽视
if(c[k]=='\0')
{
flag=1;
return;
}
if(a[i]==c[k]&&b[j]==c[k])
{
dfs(i+1,j,k+1);
dfs(i,j+1,k+1);
}else if(a[i]==c[k]&&b[j]!=c[k])
{
dfs(i+1,j,k+1);
}else if(a[i]!=c[k]&&b[j]==c[k])
{
dfs(i,j+1,k+1);
}
}
int main()
{
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
cin>>a>>b>>c;
flag=0;
memset(vis,0,sizeof(vis));
dfs(0,0,0);
printf("Data set %d: ",i);
if(flag==1) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
hdu1501 记忆化搜索。。。的更多相关文章
- hdu1501 记忆化搜索
题意: 给你三个字符串,问你前两个能不能拼成第三个串. 思路: 直接记忆化神搜就行,思路水,看下代码就知道了.这个题目我感觉最大公共子序列dp的作法是错的,虽然有人ac了,随便 ...
- [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索
1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...
- 【BZOJ-3895】取石子 记忆化搜索 + 博弈
3895: 取石子 Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 263 Solved: 127[Submit][Status][Discuss] D ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- zoj 3644(dp + 记忆化搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 思路:dp[i][j]表示当前节点在i,分数为j的路径条数,从 ...
- loj 1044(dp+记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...
- DP(记忆化搜索) + AC自动机 LA 4126 Password Suspects
题目传送门 题意:训练指南P250 分析:DFS记忆化搜索,范围或者说是图是已知的字串构成的自动机图,那么用 | (1 << i)表示包含第i个字串,如果长度为len,且st == (1 ...
- HDU1978 记忆化搜索
How many ways Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- bzoj4562: [Haoi2016]食物链--记忆化搜索
这道题其实比较水,半个小时AC= =对于我这样的渣渣来说真是极大的鼓舞 题目大意:给出一个有向图,求入度为0的点到出度为0的点一共有多少条路 从入读为零的点进行记忆化搜索,搜到出度为零的点返回1 所有 ...
随机推荐
- 【json/regex】将简单对象生成的json文进行内部排序后再输出
有这样一个实体类: package com.hy; public class Emp { private int id; private int age; private String name; p ...
- SSA与ASS字幕
SSA字幕与ASS字幕 SSA全称SubStationAlpha,是由CSLow(又称Kotus)创建的一种字幕格式,用以实现比传统字幕诸如srt等格式更为复杂的功能.SSA目前的版本为v4.00.S ...
- C++main函数命令行选项——学习笔记
atoi字符串的数转化为整数 atof转化为小数
- 实战一:LoadRunner性能测试利器
转自:https://blog.csdn.net/weixin_42350428/article/details/82106603 企业的网络应用环境都必须支持大量用户,网络体系架构中含各类应用环境且 ...
- Influxdb修改数据保留策略
retention policy: 存储策略,用于设置数据保留的时间,每个数据库刚开始会自动创建一个默认的存储策略 autogen,数据保留时间为永久,之后用户可以自己设置,例如保留最近2小时的数据. ...
- 记一次腾讯云MySQL数据库数据回滚
如题,因为操作人员的问题,需要对数据库数据进行回滚. 可以看到,设置了7天自动备份,且是物理冷备. 什么是物理冷备?科普一下: (1)热备:在数据库运行时,直接进行备份,对运行的数据库没有影响.(2) ...
- ERROR 1130:mysql 1130连接错误的有效解决方法
今天在用sqlyog连接非本地的Mysql服务器的数据库,居然无法连接很奇怪,报1130错误, ERROR 1130: Host 192.168.3.100 is not allowed to con ...
- php 微信公众平台OAuth2.0网页授权,获取用户信息代码类封装demo
get_wx_data.php <?php /** * 获取微信用户信息 * @author: Lucky hypo */ class GetWxData{ private $appid = ' ...
- 123457123456#1#----com.MC.EnglishGame98--前拼后广--jp英语-mc
com.MC.EnglishGame98--前拼后广--jp英语-mc
- Nodejs Client for FastDFS
FastDFS 是分布式文件存储系统.这个项目是FastDFS的NodeJS客户端,用来与FastDFS Server进行交互,进行文件的相关操作.我测试过的server版本是4.0.6. githu ...