2
def minPathCost(self, grid: List[List[int]], moveCost: List[List[int]]) -> int:3
max_row, max_col = len(grid), len(grid[0])4
dp = [[-1] * max_col for _ in range(max_row)]6
def recursion(row, col):7
if row == max_row - 1: # If last row then return nodes value11
): # If DP for this node is not computed then we will do so now.12
current = grid[row][col] # Current Node Value13
res = float("inf") # To store best path from Current Node14
for c in range(max_col): # Traverse all path from Current Node15
val = moveCost[current][c] + recursion(17
) # Move cost + Target Node Value21
) # DP[current node] = Best Path + Target Node Val + Current Node Val24
for c in range(max_col):25
recursion(0, c) # Start recursion from all nodes in 1st row26
return min(dp[0]) # Return min value from 1st row