#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. spider_action

    spider from mobile to mobile to mobile from selenium import webdriver from selenium.webdriver.chrome ...

  2. 3django url name详解

    打开urls.py from django.conf.urls import url from django.contrib import admin from calc import views a ...

  3. LeetCode:算法特辑——二分搜索

    LeetCode:算法特辑——二分搜索 算法模板——基础 int L =0; int R =arr.length; while(L<R) { int M = (R-L)/2+L; if(arr[ ...

  4. LeetCode:救生艇【881】

    LeetCode:救生艇[881] 题目描述 第 i 个人的体重为 people[i],每艘船可以承载的最大重量为 limit. 每艘船最多可同时载两人,但条件是这些人的重量之和最多为 limit. ...

  5. 说说JavaScript 中的new吧

    在其他语言中,new操作符都是用来实例化创建一个对象的,JavaScript 中同样如此,但是它又有一些不同.为了说清楚这个问题我们先来看一下JavaScript 中的类.原型.原型链.继承这些概念吧 ...

  6. IOS UI Frame 相对位置调整 与优化方法 Height Width X Y 调整

    不使用xib ,纯代码开发的过程中,动态UI  需要改对象的大小位置 反复使用CGRectMake 去 setFrame  非常低效耗时,而且 牵一发动全身. 以下整理出几个方法,方便动态布局 1.s ...

  7. 每天一个Linux命令(2)cd命令

    cd命令用来切换工作目录至dirname. 其中dirName表示法可为绝对路径或相对路径.若目录名称省略,则变换至使用者的home directory(也就是刚login时所在的目录).另外,~也表 ...

  8. 【leetcode刷题笔记】Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  9. 20165101 学习基础和C语言基础调查

    学习基础和C语言基础调查 技能学习心得 看了15级学长学姐丰富的技能之后,我感到很惭愧.我的课外技能可以说是很糟糕.唱歌的话,小时候还可以用假声唱一下,变声之后就是高音上不去,低音下不来.体育更是差劲 ...

  10. mini2440移植uboot 2014.04(三)

    我修改的代码已经上传到github上,地址:https://github.com/qiaoyuguo/u-boot-2014.04-mini2440.git 参考文档: s3c2440手册(下载地址) ...