#C8489. Unique Path in Grid
Unique Path in Grid
Unique Path in Grid
Given a grid of characters, where .
represents an empty cell and #
represents an obstacle, determine whether there exists exactly one unique valid path from the top-left corner to the bottom-right corner. From any cell, you are only allowed to move either right or down.
The path is considered valid if it does not go through any obstacles. If there is exactly one valid path, output YES
; otherwise, output NO
.
Note: Use dynamic programming to efficiently count the total number of paths to the destination.
inputFormat
The first line contains two integers n and m --- the number of rows and columns of the grid.
Each of the next n lines contains a string of m characters, where each character is either .
(empty cell) or #
(obstacle).
outputFormat
Output a single line: YES
if there is exactly one valid path from the top-left to the bottom-right, or NO
otherwise.
3 3
..#
.#.
...
YES