← 返回 amazon 的题目列表Top-to-Bottom Reachability and Minimum-Cost Paths in a Binary Grid
类型:online_judge
Given an m x n binary matrix, where 1 is passable and 0 is blocked, start from any passable cell in the first row. You may move to orthogonally adjacent passable cells.
Determine whether the last row is reachable.
Return all distinct simple paths from the first row to the last row. A path is a list of coordinates and cannot visit a cell twice.
Follow-up: every passable cell has a non-negative weight. The cost includes both start and end cells. Return the minimum cost from the first row to the last row, or -1 if unreachable.
CLI input is JSON: {"mode":"reachable"|"paths"|"shortest","grid":[...],"weights":[...]}.
Constraints: 1 <= m,n <= 200; enumerating all paths can be exponential.
Example
Input
{"mode":"reachable","grid":[[1,0],[1,1],[0,1]]}
Output
true