<p>In the &quot;100 game&quot; two players take turns adding, to a running total, any integer from <code>1</code> to <code>10</code>. The player who first causes the running total to <strong>reach or exceed</strong> 100 wins.</p>

<p>What if we change the game so that players <strong>cannot</strong> re-use integers?</p>

<p>For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total &gt;= 100.</p>

<p>Given two integers <code>maxChoosableInteger</code> and <code>desiredTotal</code>, return <code>true</code> if the first player to move can force a win, otherwise, return <code>false</code>. Assume both players play <strong>optimally</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> maxChoosableInteger = 10, desiredTotal = 11
<strong>Output:</strong> false
<strong>Explanation:</strong>
No matter which integer the first player choose, the first player will lose.
The first player can choose an integer from 1 up to 10.
If the first player choose 1, the second player can only choose integers from 2 up to 10.
The second player will win by choosing 10 and get a total = 11, which is &gt;= desiredTotal.
Same with other integers chosen by the first player, the second player will always win.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> maxChoosableInteger = 10, desiredTotal = 0
<strong>Output:</strong> true
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> maxChoosableInteger = 10, desiredTotal = 1
<strong>Output:</strong> true
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= maxChoosableInteger &lt;= 20</code></li>
	<li><code>0 &lt;= desiredTotal &lt;= 300</code></li>
</ul>

class Solution:
    def canIWin(self, maxChoosableInteger: int, desiredTotal: int) -> bool:
        # If the desired total is 0 or less, the first player can win trivially
        if desiredTotal <= 0:
            return True
        
        # Calculate the sum of all integers from 1 to maxChoosableInteger
        maxSum = (maxChoosableInteger * (maxChoosableInteger + 1)) // 2
        
        # If the maximum possible sum is less than the desired total, it's impossible to reach the desired total
        if maxSum < desiredTotal:
            return False
        
        # Memoization dictionary to store results of subproblems
        memo = {}
        
        # Set to keep track of numbers that have been used
        usedNumbers = set()
        
        # Recursive function to simulate the game
        def canWin(total):
            # Convert the set of used numbers to a tuple to be used as a key in the memoization dictionary
            key = tuple(sorted(usedNumbers))
            
            # If this state has already been computed, return the result from the memoization dictionary
            if key in memo:
                return memo[key]
            
            # Iterate through all the numbers that can be chosen
            for num in range(1, maxChoosableInteger + 1):
                if num not in usedNumbers:
                    # Mark the number as used
                    usedNumbers.add(num)
                    
                    # If the current player can immediately win or the next player cannot win, return True
                    if total + num >= desiredTotal or not canWin(total + num):
                        usedNumbers.remove(num)
                        memo[key] = True
                        return True
                    
                    # Unmark the number for backtracking
                    usedNumbers.remove(num)
            
            # If no winning move is found, store and return False
            memo[key] = False
            return False
        
        # Start the recursion with an initial total of 0
        return canWin(0)

# Example usage:
solution = Solution()
print(solution.canIWin(10, 11))  # Output: False
print(solution.canIWin(10, 0))   # Output: True
print(solution.canIWin(10, 1))   # Output: True
228990