Game Theory DP

You've optimized single-player decisions. Now handle two players taking turns. Solve Stone Game variants where both sides play to win.

44 lessons
152 min
Codeforces: 1700-2100LeetCode: 1700-2000

Lessons

1. Introduction to Game Theory DP

Two players, optimal play

2m

2. When to Use Game Theory DP

Alternating turns, perfect info

3m

3. Problem - Stone Game IV

LC 1510 - remove square amounts

3m1 problems

4. Stone Game IV - Why Naive Fails

Winning if opponent can lose

4m

5. Stone Game IV - Defining the DP

dp[n] = can current player win?

4m

6. Stone Game IV - Transition

Try all squares, find losing state

4m

7. Stone Game IV - Base Cases

dp[0]=false, dp[1]=true, dp[2]=false

3m

8. Stone Game IV - Implementation

O(n√n) checking squares

5m1 problems

9. Stone Game IV - Time and Space

√n moves per position

3m

10. Problem - Stone Game III

LC 1406 - take 1, 2, or 3

3m1 problems

11. Stone Game III - Why Naive Fails

Maximize score difference

4m

12. Stone Game III - Defining the DP

dp[i] = advantage from position i

4m

13. Stone Game III - Transition

Take stones, subtract opponent's best

4m

14. Stone Game III - Base Cases

dp[n] = 0, no stones left

3m

15. Stone Game III - Implementation

Right to left, O(n)

5m1 problems

16. Stone Game III - Time and Space

O(1) space with sliding window

3m

17. Nim Game - Overview

XOR piles, zero = lose

3m1 problems

18. Nim Game - Why Naive Fails

XOR trick explained

4m

19. Nim Game - Defining the DP

Grundy = mex of reachable states

4m

20. Nim Game - Core Logic

mex = minimum excludant

4m

21. Lessons from Nim Game

XOR Grundy for combined games

3m

22. Staircase Nim - Why Odd Steps Matter

23. Staircase Nim - Winning Strategy

24. Staircase Nim - Problem Pattern

Odd steps only matter

4m1 problems

25. Staircase Nim - Implementation

Even-to-odd = adding to Nim

4m

26. Composite Games - Sprague-Grundy Theorem

XOR Grundy numbers

4m

27. Computing Grundy Numbers

mex of reachable Grundy values

4m1 problems

28. Game on DAG - Applying Grundy

Topological order on DAG

4m1 problems

29. Problem - Stone Game I

LC 877 - pick from ends

3m1 problems

30. Stone Game I - Solution

Interval DP or math trick

4m

31. Stone Game I - One-Liner

Alice always wins (odd total)

3m

32. Problem - Stone Game VII

LC 1690 - score = remaining sum

3m1 problems

33. Stone Game VII - Solution

Remove stone, score the rest

4m

34. Stone Game VII - Implementation

Prefix sums for range totals

3m1 problems

35. Quiz: Game Theory Patterns

Which game pattern is this?

3m1 problems

36. Quiz: Game Theory Edge Cases

Single pile, symmetric games

3m1 problems

37. Common Mistakes in Game Theory DP

Whose turn? Score difference handles it

4m

38. Problem - Cat and Mouse

LC 913

3m1 problems

39. Cat and Mouse - Implementation

Solution approach

5m1 problems

40. Problem - Stone Game VIII

LC 1872

3m1 problems

41. Stone Game VIII - Implementation

Solution approach

5m1 problems

42. Problem - Grundy's Game

CSES 2207

3m1 problems

43. Grundy's Game - Implementation

Solution approach

5m1 problems

44. Section Recap

From win/lose to Grundy

3m

Practice Problems

1.
A Lot of Gamescodeforces
2.
Berzerkcodeforces
3.

Ready to start learning?

Access all 44 lessons with interactive content and progress tracking.