Welcome to the "Can I Win" strategy game! This is a fascinating twist on the classic number-picking game where two players compete to reach a target total, but with a crucial constraint: no number can be used twice.
The Game Rules:
- Two players take turns picking integers from
1tomaxChoosableInteger - Each number can only be used once (no replacement)
- Numbers are added to a running total
- The first player to make the total reach or exceed
desiredTotalwins - Both players play optimally (always make the best possible move)
Your Task: Determine if the first player can guarantee a win with optimal play. Return true if the first player has a winning strategy, false otherwise.
Example: With numbers 1-10 and target 11, the first player can pick 10, then no matter what the second player picks (1-9), the first player can reach 11+ on their next turn!
Input & Output
Visualization
Time & Space Complexity
There are 2^n possible game states (bitmasks), and for each state we try at most n moves, but each state is computed only once
Memoization table stores results for up to 2^n different game states
Constraints
- 1 <= maxChoosableInteger <= 20
- 0 <= desiredTotal <= 300
- Both players play optimally
- Numbers from 1 to maxChoosableInteger can each be used at most once