Given a grid of integers and a moveCost table, return the minimum cost to travel from any cell in the first row to any cell in the last row. The value of the current cell determines the transition cost to the next row. Pattern focus: Grid Min Max Path DP. The transition cost depends on the current cell value and the next-column choice.
grid values index into moveCost
minimum travel cost across rows
Example 1:
Input:
grid = [[5,3],[4,0],[2,1]] moveCost = [[9,4],[6,7],[5,8],[7,4],[6,9],[5,7]]
Output:
12
Explanation:
The minimum path cost is 12.
Example 2:
Input:
grid = [[5,1,2],[4,0,3]] moveCost = [[2,1,3,4],[0,2,1,3],[3,1,2,0],[4,2,1,1],[1,0,2,3],[2,1,1,2]]
Output:
3
Explanation:
The best route has cost 10.
Example 3:
Input:
grid = [[1,2],[3,4]] moveCost = [[0,1],[1,0],[2,3],[3,2]]
Output:
5
Explanation:
A compact grid example has minimum cost 5.