打卡记录
网格中的最小路径代价(动态规划)
链接
class Solution:def minPathCost(self, grid: List[List[int]], moveCost: List[List[int]]) -> int:m, n = len(grid), len(grid[0])f = [[0x3f3f3f3f3f] * n for _ in range(m)]f[0] = grid[0]for i in range(1, m):for j in range(n):for k in range(n):idx = grid[i - 1][k]f[i][j] = min(f[i][j], f[i - 1][k] + moveCost[idx][j] + grid[i][j])return min(f[-1])