Dynamic Programming21 sections · 916 units
Open in Course

Pattern - Probability DP

Core idea

When you see a problem with random transitions, think probability DP. The pattern:

1.1. State: what you need to know (position, resources, moves left).

2.2. Transition: dp[state]=pidp[nexti]dp[state] = \sum p_i \cdot dp[next_i] where pip_i is the probability of transition ii.

3.3. Base cases: terminal states where probability is 00 or 11 (or 0.50.5 for ties). For counting paths, replace probability weights with counts. For expected values, weight by outcomes instead of just probabilities.