Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 464 Can I Win - Key Idea

Bitmask meets game theory

State: which numbers have been used. With n20n \leq 20, a bitmask works perfectly. Bit ii set means number i+1i+1 is used.

Winning condition: current player can pick a number that either wins immediately (total \geq target) or leaves opponent in a losing state. We don't need to track whose turn it is. The current player is always "me" in the recursion. If I can win from this state, the state is winning.