Tempter of the Bone

Problem Description

The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.

The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.

Input

The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following:

'X': a block of wall, which the doggie cannot enter; 
'S': the start point of the doggie; 
'D': the Door; or
'.': an empty block.

The input is terminated with three 0's. This test case is not to be processed.

Output

For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.

Sample Input

4 4 5

S.X.

..X.

..XD

....

3 4 5

S.X.

..X.

...D

0 0 0

Sample Output

NO

YES

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7.  
  8. int N,M,T;
  9. char map[][];
  10. bool visit[][];
  11. int to[][]= {{,},{-,},{,},{,-}};
  12. int a,b,flag;
  13.  
  14. void dfs(int x,int y,int ans)
  15. {
  16. if(x==a && y==b)
  17. {
  18. if(ans==T)
  19. flag=;
  20. return;
  21. }
  22. if(ans>=T) return;
  23. if(map[x][y]!='X')
  24. {
  25. for(int i=; i<; i++)
  26. {
  27. int xx=x+to[i][];
  28. int yy=y+to[i][];
  29. if(xx>= && xx<N && yy>= && yy<M && !visit[xx][yy] && map[xx][yy]!='X')
  30. {
  31. visit[xx][yy]=true;
  32. dfs(xx,yy,ans+);
  33. if(flag==) return;
  34. visit[xx][yy]=false;
  35. }
  36. }
  37. }
  38. }
  39.  
  40. int main()
  41. {
  42. while(scanf("%d%d%d",&N,&M,&T)== && (N+M+T))
  43. {
  44. getchar();
  45. int x,y;
  46. for(int i=; i<N; i++)
  47. {
  48. for(int j=; j<M; j++)
  49. {
  50. cin>>map[i][j];
  51. if(map[i][j]=='S')
  52. x=i,y=j;
  53. if(map[i][j]=='D')
  54. a=i,b=j;
  55. }
  56. getchar();
  57. }
  58. if(abs(x-a)+abs(y-b)>T || ((a+b)+(x+y)+T)%==)
  59. {
  60. puts("NO");
  61. continue;
  62. }
  63. memset(visit,false,sizeof(visit));
  64. flag=;
  65. visit[x][y]=true;
  66. dfs(x,y,);
  67. if(flag==) puts("YES");
  68. else puts("NO");
  69. }
  70. return ;
  71. }

hdu1010 dfs+奇偶性减枝的更多相关文章

  1. poj1753 bfs+奇偶性减枝//状压搜索

    http://poj.org/problem?id=1753 题意:有个4*4的棋盘,上面摆着黑棋和白旗,b代表黑棋,w代表白棋,现在有一种操作,如果你想要改变某一个棋子的颜色,那么它周围(前后左右) ...

  2. hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...

  3. ZOJ 1609 Equivalence(状压+dfs减枝)

    ZOJ Problem Set - 1609 Equivalence Time Limit: 5 Seconds      Memory Limit: 32768 KB When learning m ...

  4. 模型压缩,模型减枝,tf.nn.zero_fraction,统计0的比例,等。

    我们刚接到一个项目时,一开始并不是如何设计模型,而是去先跑一个现有的模型,看在项目需求在现有模型下面效果怎么样.当现有模型效果不错需要深入挖掘时,仅仅时跑现有模型是不够的,比如,如果你要在嵌入式里面去 ...

  5. hdu6183 Color it 线段树动态开点+查询减枝

    题目传送门 题目大意: 有多次操作.操作0是清空二维平面的点,操作1是往二维平面(x,y)上放一个颜色为c的点,操作2是查询一个贴着y轴的矩形内有几种颜色的点,操作3退出程序. 思路: 由于查询的矩形 ...

  6. HDU 1010 Tempter of the Bone (广搜+减枝)

    题目链接 Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. How ...

  7. hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...

  8. hdu-1010 dfs+剪枝

    思路: 剪枝的思路参考博客:http://www.cnblogs.com/zibuyu/archive/2012/08/17/2644396.html  在其基础之上有所改进 题意可以给抽象成给出一个 ...

  9. hdu 1010 走到终点时刚好花掉所有时间 (DFS + 奇偶性剪枝 )

    题意:输入一个n*m的迷宫,和一个T:可以在迷宫中生存的最大时间.S为起点,D为终点.并且,每个格子只能踩一次,且只能维持一秒,然后该块地板就会塌陷.所以你必须每秒走一步,且到D点时,所用时间为T.用 ...

随机推荐

  1. windows server 2008 配置安装AD 域控制器

    工作需要,搞起AD域来,具体配置如下: 配置环境 Windows版本:Windows Server 2008 R2 Enterprise Service Pack 1 系统类型: 64 位操作系统 配 ...

  2. 安装Django,运行django-admin.py startproject 工程名,后不出现指定的工程解决办法!!

       第一次写博客,,,,, 在看我这篇教程的前提是你应该已经正确装好python和Django了,好了,废话不说了,正题走你!你现在是不是很纠结自己运行django-admin.py startpr ...

  3. php面向对象中的静态与抽象,接口

    静态又包括: 普通成员: 普通成员是属于对象的 静态成员: 静态成员是属于类的 关键字:static self关键字:在类里面代表该类,前面不用加$ 在静态方法里面不能调用普通成员 在普通方法里面能够 ...

  4. apache vhost

    httpd.conf: Include "F:/wamp/alias/*" <Directory "F:\wamp\www">    Options ...

  5. Qt 获取Mac地址

    QList<QNetworkInterface> list = QNetworkInterface::allInterfaces(); foreach(QNetworkInterface ...

  6. WIN7 64位系统下,右下角的声音和电源图标不见的解决办法

    近日,电脑突然出现任务栏右下角的声音和电源图标消失不见的问题,重启仍旧没有修复,后来找到了解决办法 解决办法: 1.Ctrl+Shift+Esc键调出windows资源管理器. 2.找到进程中的exp ...

  7. 【Mongodb】3.X 配置身份验证

    配置身份验证详解: 开启认证: 启动MongoDB./mongodb --syslog --fork --port 20000  --auth 1.如果不添加参数:auth,表明用默认的root的权限 ...

  8. NYOJ题目1162数字

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr8AAAJ/CAIAAAD+kywNAAAgAElEQVR4nO3dO1LjzN4H4G8T5CyE2A ...

  9. 20145206邹京儒《Java程序设计》第4周学习总结

    20145206 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 6.1 何谓继承 继承基本上就是避免多个类间重复定义共同行为 package cc.openhome; pu ...

  10. 查看局域网内在线的主机ip和mac地址

    ]# nmap -sP Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-12 22:43 CST Nmap scan report for 192. ...