#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<queue>
#include<vector>
using namespace std;
const int MAX_N=;
vector<string> words;
map<string, bool> vis;
queue<string> que;
bool dfs(int i,string word)
{
int len=word.length();
if(word[len-]=='m')
{
return true;
}
if(i==words.size())
{
return false;
} for(int j=; j<words.size(); j++)
{
string s=words[j];
if(!vis[s]&&word[len-]==s[])
{
vis[s]=true;
if(dfs(i+,s))
return true;
vis[s]=false;
}
}
return false;
} void Judge()
{
bool flag=false; while(que.size()!=)
{
map<string,bool>::iterator it;
for(it=vis.begin(); it!=vis.end(); it++)
{
it->second=false;
}
string s=que.front();
que.pop();
vis[s]=true;
if(dfs(,s))
{
flag=true;
break;
}
} while(!que.empty())
{
que.pop();
}
if(flag)
{
printf("Yes.\n");
}
else
{
printf("No.\n");
}
}
int main()
{
string s;
while(cin>>s)
{
if(s.compare("")==)
{
Judge();
words.clear();
vis.clear();
continue;
}
words.push_back(s);
if(s[]=='b')
{
que.push(s);
}
} return ;
}

HDOJ1181(简单DFS)(练习使用STL)的更多相关文章

  1. Red and Black(简单dfs)

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. POJ 1979 Red and Black (简单dfs)

    题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...

  3. POJ1573(Robot Motion)--简单模拟+简单dfs

    题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...

  4. POJ1979 Red and Black (简单DFS)

    POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

  5. CF760 C. Pavel and barbecue 简单DFS

    LINK 题意:给出n个数,\(a_i\)代表下一步会移动到第\(a_i\)个位置,并继续进行操作,\(b_i\)1代表进行一次翻面操作,要求不管以哪个位置上开始,最后都能满足 1.到达过所有位置 2 ...

  6. uva 784 Maze Exploration(简单dfs)

    这道题看上去非常麻烦,什么迷宫啊.门之类的,事实上挺简单的,就是让把与 * 连通的都置为 # 包含 * , 直接dfs就能够了,只是我wa了好多次...最后居然是多读了一个换行.忘了加getchar( ...

  7. poj 2386:Lake Counting(简单DFS深搜)

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18201   Accepted: 9192 De ...

  8. BZOJ3991 [SDOI2015]寻宝游戏 【dfs序 + lca + STL】

    题目 小B最近正在玩一个寻宝游戏,这个游戏的地图中有N个村庄和N-1条道路,并且任何两个村庄之间有且仅有一条路径可达.游戏开始时,玩家可以任意选择一个村庄,瞬间转移到这个村庄,然后可以任意在地图的道路 ...

  9. 题解报告:hdu 1312 Red and Black(简单dfs)

    Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

随机推荐

  1. UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)

    今天使用MySQLdb往MySQL插入中文数据遇到一个异常: UnicodeEncodeError: 'latin-1' codec can't encode characters in positi ...

  2. mysql 修改表名的方法:sql语句

    在使用mysql时,经常遇到表名不符合规范或标准,但是表里已经有大量的数据了,如何保留数据,只更改表名呢? 可以通过建一个相同的表结构的表,把原来的数据导入到新表中,但是这样视乎很麻烦. 能否简单使用 ...

  3. 数据库连接理解——JDBC

    需求:数据库操作 数据是:用户信息 1.连接数据库  JDBC Hibernate 2.操作数据库 c create r read u update d delete 3.关闭数据库连接 interf ...

  4. Docker alpine 设置东八时区

    FROM alpine:3.8 RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories &a ...

  5. rail模型

    rail是一种以用户为中心的性能模型,又google提出,其主要目标是让用户满意,主要分为response animation idle load四个部分 response 输入延迟时间小于100毫秒 ...

  6. Delphi 的类型与指针

    Delphi 的指针分为 "类型指针" 和 "无类型指针" 两类.Delphi 中的类型, 常用的也得有几百个, 我们可以给每种类型定义相应的类型指针.其实 D ...

  7. HDU 2736 Surprising Strings

                                    Surprising Strings Time Limit:1000MS     Memory Limit:65536KB     64 ...

  8. Jquery实现动态导航栏和轮播导航栏

    动态导航栏和轮播导航栏的实现思想: 利用jquery技术的append()方法和bind()方法实现li标签的添加和点击事件绑定,在利用$getJSON(url,data,function)请求方法实 ...

  9. Linux课程---6、别名管理和网络配置(Linux命令如何记)

    Linux课程---6.别名管理和网络配置(Linux命令如何记) 一.总结 一句话总结: 理解记忆:因为命令要实现那么多功能,必须有那么多参数,而不同的参数就适用不用的情况 命令基本格式:命令关键字 ...

  10. IDEA 加载Eclipse项目