1
var knightProbability = function (n, k, row, column) {13
const dp = Array(k + 1)18
.map((_) => Array(n).fill(0))21
const isOut = (pos) => pos < 0 || pos > n - 1;22
const move = (x = row, y = column, step = k) => {23
if (step === 0) return 1;24
const moves = dp[step][x][y];25
if (moves !== 0) return moves;27
for (const [mvoeX, moveY] of dirs) {28
const nextX = x + mvoeX;29
const nextY = y + moveY;30
if (isOut(nextX) || isOut(nextY)) continue;32
dp[step][x][y] += move(nextX, nextY, step - 1);34
return dp[step][x][y];38
return dp[k][row][column] / 8 ** k;