最后这样可以ac js代码const row_max = input.length - 1;
const col_max = input[0].length - 1;
function consum(m, n) {
if (m < 0 || n < 0) return Number.POSITIVE_INFINITY;
if (m === 0 && n === 0) return 0;
let res = 0;
let cost_this = 0;
if (input[m][n] === 0) {
cost_this = 2;
} else if (input[m][n] === 1) {
cost_this = 1;
} else {
cost_this = Number.POSITIVE_INFINITY;
}
res = Math.min(consum(m - 1, n) + cost_this, consum(m, n - 1) + cost_this);
return res;
}
console.log(consum(row_max, col_max));