← 返回 amazon 的题目列表Shortest Path with Shortcuts
类型:online_judge
Given a m x n matrix representing a board where some cells contain shortcuts, and transitioning between shortcuts is negligible. Your task is to find the shortest path from the top-left corner to the bottom-right corner of the board. You may choose to use the shortcuts under certain conditions, provided the path adheres to cell constraints. Provide several test cases for your solution.
Input: Integers m, n and a m x n matrix grid where 1 represents walkable cells, 0 represents non-walkable cells, and 'S' represents usable shortcuts.
Output: An integer representing the number of steps in the shortest path.
Example:
Input: 3 3 1 S 1 1 0 1 S 1 1
Output: 2
Constraints:
1 <= m, n <= 100
Total number of cells in the matrix is at most 10,000.
Example
Input
3 3
1 S 1
1 0 1
S 1 1