|
escape-1
We need to escape from a maze in at most S steps. The maze contains:
0-marked freely passable cells.
^v<>-marked free cells -
for these, we can only enter from a specific direction: only from
below,above,from the right,from the left respectively. But we can exit
in any direction (following the rules).
1-marked forbidden cells: cannot
step on them, cannot start from them In one move, we can step to a
horizontally or vertically adjacent free cell. If we reach the edge of
the maze, we have escaped… Determine how many internal (not on the
edges) free cells
()
exist such that starting from there, we can escape within
steps.
Input specification
The first line contains
,
the number of mazes. Description of a maze: First line: three numbers
(maximum steps, rows, columns). Then
lines follow: each containing a string of length
with the characters described above.
Output specification
lines, each containing the requested number
.
Constraints
Sample input 1
52 4 41111100110110v112 4 41111100110110>111 4 41001100110110v113 5 50010000^001<0>100v00001006 5 50010000^001<0>100v0000100
download as text file
Sample output 1
20399
download as text file
|
|