1
var minPathCost = function (grid, moveCost) {2
const dfs = (r, c, dp) => {3
if (r === grid.length || c === grid[r].length) return 0;4
if (dp[r][c] !== undefined) return dp[r][c];7
const cost = grid[r][c],10
if (nextRow === grid.length) return cost;12
let nextMoveCost = Number.MAX_SAFE_INTEGER;13
for (let nextCol = 0; nextCol < grid[nextRow].length; nextCol++) {14
nextMoveCost = Math.min(16
dfs(nextRow, nextCol, dp) + moveCost[cost][nextCol] /*path cost*/20
cost + (nextMoveCost === Number.MAX_SAFE_INTEGER ? 0 : nextMoveCost));23
let minCost = Number.MAX_SAFE_INTEGER;24
const dp = Array(grid.length)26
.map(() => Array(grid[0].length).fill());27
for (let c = 0; c < grid[0].length; c++) {28
minCost = Math.min(minCost, dfs(0, c, dp));