Dynamic Programming21 sections · 916 units
Open in Course

Knight Probability - State Definition

What dp[r][c][k] means

Define dp[r][c][k]dp[r][c][k] = the probability that a knight starting at (r,c)(r, c) with kk moves remaining stays on the board for all kk moves. The answer we want is dp[row][col][K]dp[row][col][K] where (row,col)(row, col) is the starting position and KK is the total number of moves.

Why this state? It captures everything that matters: where you are and how many moves are left. Given your current position and remaining moves, the future probability depends only on these values, not on the path you took to get here (Markov property).