Game Theory DP

You've used DP for optimization. Game Theory DP handles two players taking turns with optimal moves.

46 lessons
201 min
Codeforces: 1700-2400LeetCode: 1900-2300

Lessons

1. Intro

The Goal

5m

2. Vocabulary - Optimal Play

Both play perfectly

5m

3. Winning and Losing States

The foundation

5m

4. Quiz: Winning vs Losing

State classification

3m1 problems

5. The Minimax Principle

My best against their best

5m

6. Quiz: Minimax Basics

Knowledge check

3m1 problems

7. LeetCode 486 Predict the Winner - Problem Statement

LeetCode 486

5m1 problems

8. LeetCode 486 Predict the Winner - Key Idea

Score difference trick

5m

9. LeetCode 486 Predict the Winner - State Design

Dp[i][j] for range

5m

10. LeetCode 486 Predict the Winner - Transition

Left or right choice

6m

11. LeetCode 486 Predict the Winner - Implementation

The code

6m1 problems

12. LeetCode 486 Predict the Winner - Walkthrough

Tracing the game

4m

13. Challenge: First Player Advantage

When does first move help?

4m

14. Quiz: Predict the Winner

Knowledge check

3m1 problems

15. LeetCode 1140 Stone Game II - Problem Statement

LeetCode 1140

5m1 problems

16. LeetCode 1140 Stone Game II - Key Idea

Track M parameter

5m

17. LeetCode 1140 Stone Game II - State Design

Dp[i][M]

5m

18. LeetCode 1140 Stone Game II - Implementation

With suffix sums

6m1 problems

19. LeetCode 1140 Stone Game II - Walkthrough

Tracing with M parameter

4m

20. Challenge: Stone Game Variants

Exploring modifications

4m

21. Quiz: Stone Game II

Knowledge check

3m1 problems

22. LeetCode 464 Can I Win - Problem Statement

LeetCode 464

5m1 problems

23. LeetCode 464 Can I Win - Key Idea

Bitmask meets game theory

5m

24. LeetCode 464 Can I Win - State Design

Dp[mask]

5m

25. LeetCode 464 Can I Win - Implementation

Memoization with bitmask

6m1 problems

26. LeetCode 464 Can I Win - Walkthrough

Tracing with bitmask

4m

27. Quiz: Can I Win State

Understanding the bitmask

3m1 problems

28. Quiz: Can I Win

Knowledge check

3m1 problems

29. Lessons from Game Theory DP

summary

8m

30. Nim Game - Problem Statement

The classic game

3m

31. Nim Game - Mathematical Insight

Beyond brute force

4m

32. Divisor Game - Problem Statement

Division-based moves

3m

33. Quiz: Divisor Game Pattern

Proving the pattern

3m1 problems

34. Stone Game IV - Problem Statement

Perfect square moves

3m

35. Stone Game IV - Implementation

Efficient computation

5m

36. Flip Game II - Problem Statement

String transformation game

3m

37. Sprague-Grundy Introduction

Combining independent games

4m

38. Quiz: Sprague-Grundy Basics

Understanding nimbers

3m1 problems

39. Cat and Mouse - Problem Statement

Two-agent chase

3m

40. Cat and Mouse - Implementation

Handling draws

5m

41. Quiz: Game with Draws

Three outcomes

3m1 problems

42. Pattern - Game Theory DP

Recognizing and solving

4m

43. Challenge: Non-Zero-Sum Games

Beyond win/lose

4m

44. Challenge: More Than Two Players

Multi-agent games

4m

45. What's Next

Preview of Probability DP

4m

46. Section Recap

What we learned

8m

Practice Problems

1.
Predict the WinnerLeetCodemedium

Foundational minimax game theory with optimal play

2.
Stone Game IILeetCodemedium

Classic minimax DP with variable M parameter

3.
Stoned GameCodeforcesmedium

Teaches optimal play and game-ending conditions

4.
Can I WinLeetCode

Covered with full walkthrough in this section.

5.
Stoned GameCodeforcesmedium

Alternate picking from piles. Greedy insight when one pile dominates.

6.
Palindrome Game (Easy)Codeforcesmedium

Two-player game on palindrome string. Analysis of symmetric vs asymmetric cases.

7.
Erase and Extend (Easy)Codeforcesmedium

Build lexicographically smallest string. Game-like decision at each step.

8.
Permutation GameCodeforcesmedium

Move token on permutation. DP on DAG to determine winning positions.

9.
Game of NIM-likeCodeforcesmedium

Subtract 1 or divide by k. Grundy number analysis with special structure.

10.
Up the Strip (Simple)Codeforcesmedium

Count paths with subtract or divide moves. DP with harmonic sums.

11.
Power SequenceCodeforcesmedium

Transform array to geometric sequence. Minimize total changes optimally.

12.
Stone GameLeetCodemedium

First player always wins with even piles. Math insight or interval DP.

13.
Stone Game IILeetCodemedium

Take 1 to 2M piles, M grows. Minimax DP with expanding parameter.

14.
Stone Game IIILeetCodehard

Take 1-3 stones from front. Classic minimax with suffix DP.

15.
Stone Game IVLeetCodehard

Remove square number stones. Sprague-Grundy with perfect squares.

16.
Stone Game VLeetCodehard

Split row, keep smaller half. Interval DP maximizing Alice score.

17.

Classic stone game - determine winner with optimal play. Foundation for game theory DP.

18.

Two-player deque game - interval DP meets game theory. Maximize your score difference.

Ready to start learning?

Access all 46 lessons with interactive content and progress tracking.