#K70892. Taco Grid Health Path
Taco Grid Health Path
Taco Grid Health Path
In this problem, you are given a grid of size (n \times m) where each cell can be one of the following characters:
- .: an empty space
- #: a wall, which cannot be traversed
- T: a trap cell that deals extra damage
- H: a health cell that restores some health
Formally, given integers (n) and (m), a grid (G) of (n) rows and (m) columns (each cell (G_{i,j}) being one of the characters {'.', '#', 'T', 'H'}), and three integers: initial health (H_0), trap damage (D), and health restored (R), determine if there exists a path from ((0,0)) to ((n-1, m-1)) such that at every step the health remains positive.
The problem involves concepts from grid traversal and state management, and you are encouraged to use efficient search algorithms (like breadth-first search) to solve it.
inputFormat
The input is read from stdin and has the following format:
- The first line contains two integers (n) and (m), representing the number of rows and columns of the grid.
- The next (n) lines each contain a string of length (m) representing the grid row. The characters in the string are among '.', '#', 'T', and 'H'.
- The last line contains three integers: health (the initial health), trap_damage (the additional damage incurred on a trap cell), and health_restored (the health gained when stepping on a health cell).
outputFormat
The output is written to stdout. Print a single line containing either "YES" if it is possible to reach the bottom-right cell with positive health, or "NO" otherwise.## sample
4 4
...#
.#..
.T.#
H...
10 2 3
YES