Tempter of the Bone
题目描述
\(N \times M\)的棋盘上有一粒棋子,每次棋子可以选择向上、下、左、右四个方向之一移动一格。棋盘上有一些障碍,棋子不能移到有障碍的地方。能否让棋子从某个位置出发,移动 刚好 \(T\)步后到达另一个指定位置?棋子不能重复到达一个位置(包括起点和终点)多次。
原版的英文题面如下:
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.
I/O格式
输入
每个输入文件包含多组测试数据,每组数据的格式如下:
第一行是三个正整数\(N,M,T\),分别表示棋盘的行数、列数,以及要走的步数,\(N=M=T=0\)则表示输入结束;
之后\(N\)行以字符串的形式描述该棋盘。字符S
表示起点,D
表示终点,X
表示障碍,.
表示可以走的空地。
\(2 \le N,M \le 6; \phantom{x} 1 \le T < 50\)
对于76%的数据:数据组数\(\le 200\);
对于100%的数据:数据组数\(\le 5000\)。
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.
输出
每组数据输出一行,如果存在方案则输出YES
,否则输出NO
。
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
样例
输入
4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
输出
NO
YES
来源
HDU Online Judge P1010:http://acm.hdu.edu.cn/showproblem.php?pid=1010