1
var pathsWithMaxScore = function (board) {8
.map(() => [-Infinity, 0])10
let mod = 10 ** 9 + 7;11
dp[n - 1][n - 1] = [0, 1]; // [max score, number of paths]13
for (let i = n - 1; i >= 0; i--) {14
for (let j = n - 1; j >= 0; j--) {15
if (board[i][j] === "X" || board[i][j] === "S") continue;17
let paths = [dp[i][j + 1], dp[i + 1][j + 1], dp[i + 1][j]];18
for (let [maxScore, numPaths] of paths) {19
if (dp[i][j][0] < maxScore) {20
dp[i][j] = [maxScore, numPaths];21
} else if (dp[i][j][0] === maxScore) {22
dp[i][j][1] = (dp[i][j][1] + numPaths) % mod;25
let score = board[i][j] === "E" ? 0 : Number(board[i][j]);29
return dp[0][0][1] === 0 ? [0, 0] : dp[0][0];