• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

HDU-1181 变形课

题意:给出n个单词,判断是否存在以‘b’开头,‘m’结尾的情况。

思路:dfs.

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1181

 

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <cmath>
 5 #include <string>
 6 #include <algorithm>
 7 #include <iostream>
 8 using namespace std;
 9 const int N=10010;
10 
11 string str[N];
12 bool vis[N],flag;
13 int cnt;
14 
15 void dfs(char c){
16     if(c=='m'){flag=true;return ;}
17     for(int i=0;i<cnt;i++){
18         if(!vis[i]&&str[i][0]==c){
19             vis[i]=true;
20             dfs(str[i][str[i].length()-1]);
21             vis[i]=false;
22         }
23     }
24 }
25 
26 int main(){
27     
28 //    freopen("data.in","r",stdin);
29 //    freopen("data.out","w",stdout);
30     
31     cnt=0;
32     while(cin>>str[cnt++]){
33         if(str[cnt-1]=="0"){
34             memset(vis,false,sizeof(vis));
35             flag=false;
36             dfs('b');
37             if(flag) puts("Yes.");
38             else puts("No.");
39             cnt=0;
40         }    
41     }
42     return 0;
43 }
posted @ 2012-06-18 08:56  Hug_Sea  阅读(145)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3