Dynamic Programming21 sections · 916 units
Open in Course

Knight Probability - Walkthrough

Tracing the transitions

A knight starts at (r,c)(r, c) on an n×nn \times n board. After kk moves, what's the probability it's still on the board? dp[step][r][c]dp[step][r][c] = probability of being at (r,c)(r, c) after stepstep moves, starting from the initial position.

Initial: dp[0][r0][c0]=1dp[0][r_0][c_0] = 1. Transition: each cell distributes its probability equally to 8 knight-move destinations. After kk steps, sum all dp[k][r][c]dp[k][r][c] for valid (r,c)(r, c). Moves that go off-board contribute to the "off-board" probability.