#P6207. Finding a Valid Path in a Grid with Obstacles
Finding a Valid Path in a Grid with Obstacles
Finding a Valid Path in a Grid with Obstacles
Farmer John has divided his farm into an grid. Some regions of the farm are impassable. Bessie is initially at cell and is eager to have dinner at the barn located at cell . It is guaranteed that starting from cell there exists at least one valid path to when moving only to the four adjacent cells (up, down, left, right). Your task is to output any one valid path with no more than moves.
Note: This problem uses Special Judge.
inputFormat
The input begins with a line containing two integers and , representing the number of rows and columns in the grid. The following lines each contain a string of characters. A cell with a dot .
indicates a free cell and a #
indicates an impassable cell. It is guaranteed that the cells and are free, and that there exists at least one valid path.
outputFormat
Output a string consisting of the characters U
, D
, L
, and R
. This string represents the sequence of moves Bessie takes to reach the barn. The path must be valid and contain at most moves.
sample
3 3
...
.#.
...
DDRR