Probability DP

You know deterministic DP. Now handle randomness. Compute probabilities and expected values.

44 lessons
178 min
Codeforces: 1700-2300LeetCode: 1800-2300

Lessons

1. Intro

What you'll learn

4m

2. Core Concept

Expected values

4m

3. Vocabulary - Expected Value

Average outcome

4m

4. Quiz: Expected Value

Understanding expectation

3m1 problems

5. Vocabulary - Transition Probability

Weighted edges

4m

6. The Key Formula

Weighted sum

4m

7. Quiz: Linearity of Expectation

A powerful property

3m1 problems

8. LeetCode 688 Knight Probability in Chessboard - Problem Statement

LeetCode 688

3m1 problems

9. Knight Probability - The Setup

Understanding the grid

4m

10. Knight Probability - State Definition

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

4m

11. Knight Probability - Transition

Eight directions

4m

12. Knight Probability - Base Cases

Boundaries

4m

13. Knight Probability - Implementation

The code

7m1 problems

14. Knight Probability - Walkthrough

Tracing the transitions

4m

15. Lessons from Knight Probability

summary

4m

16. Challenge: Knight Expected Moves

Expected value variant

4m

17. LeetCode 576 Out of Boundary Paths - Problem Statement

LeetCode 576

3m1 problems

18. Out of Boundary - State Definition

Position and moves

4m

19. Out of Boundary - Transition

Four directions

4m

20. Out of Boundary - Implementation

The code

7m1 problems

21. Out of Boundary - Walkthrough

Counting paths with probability

4m

22. Lessons from Out of Boundary

summary

4m

23. Quiz: Out of Boundary Counting

Counting vs probability

3m1 problems

24. LeetCode 808 Soup Servings - Problem Statement

LeetCode 808

3m1 problems

25. LeetCode 808 Soup Servings - The Observation

Scaling trick

5m

26. LeetCode 808 Soup Servings - State Definition

Remaining amounts

5m

27. LeetCode 808 Soup Servings - Transition

Four operations

5m

28. LeetCode 808 Soup Servings - Implementation

The code

7m1 problems

29. LeetCode 808 Soup Servings - Walkthrough

Understanding the approximation

4m

30. Lessons from Soup Servings

summary

4m

31. Quiz: Soup Approximation

Why the threshold works

3m1 problems

32. Pattern - Probability DP

Core idea

4m

33. LeetCode 837 New 21 Game - Problem Statement

Card drawing probability

3m1 problems

34. LeetCode 837 New 21 Game - Implementation

Sliding window optimization

5m1 problems

35. Quiz: New 21 Game Stopping

Understanding the constraint

3m1 problems

36. Random Point in Circle - Problem Statement

Geometric probability

3m

37. Toss Strange Coins - Problem Statement

Probability with different coins

3m

38. Toss Strange Coins - Implementation

Space optimization

5m

39. Dice Roll Simulation - Problem Statement

Constrained sequences

3m

40. Quiz: Dice Roll States

State design choices

3m1 problems

41. Challenge: Infinite Expected Value

When expectation diverges

4m

42. Pattern - When to Use Probability DP

Recognizing the pattern

4m

43. What's Next

Preview of D&C Optimization

4m

44. Section Recap

What we learned

5m

Practice Problems

1.

Perfect intro - calculate probability of more heads than tails with different coin probabilities.

2.

Probability that sum of n dice falls in a range - clean transitions.

3.
Ilya and EscalatorCodeforcesmedium

Expected value with time-based probability transitions.

4.
Bag of MiceCodeforcesmedium

Game theory + probability with alternating turns.

5.

Classic expected value - random selection until all dishes empty.

6.
New 21 GameLeetCodemedium

Sliding window optimization for probability DP.

7.

Covered with full walkthrough in this section.

8.

Covered with full walkthrough in this section.

9.

Covered with full walkthrough in this section.

10.
Bad Luck IslandCodeforcesmedium

Rock-paper-scissors survival. 3D probability DP with transition matrix.

11.
Jon and OrbsCodeforcesmedium

Expected days to collect k distinct orbs. DP on collected count.

12.
Ilya and EscalatorCodeforcesmedium

Expected people on escalator. Probability DP with time steps.

13.
Omkar and Bed WarsCodeforcesmedium

Minimum changes for valid circular attack. DP on consecutive segments.

14.
Tree ArrayCodeforceshard

Expected inversions in BFS order. Probability DP on tree structure.

15.
Beautiful MirrorsCodeforceshard

Expected days to pass all mirrors. Linear recurrence with restart.

16.

Classic probability puzzle. Recurrence reveals beautiful 0.5 answer.

17.

Count valid distributions. Combinatorics + probability with DP.

Ready to start learning?

Access all 44 lessons with interactive content and progress tracking.