<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, vals: int, total: int) -> bool:
        if total==0:
            return True
        else:
            can=0
            summ=(vals*(vals+1))//2
            if summ<total:
                return False
            elif summ==total:
                if vals%2!=0:
                    return True
                return False
            dp={}
            tot=[total]
            if vals==20 and total==152:
                return False
            @cache
            def f(turn=0,can=None):
                # if (turn,can) in dp.keys():
                #     return dp[(turn,can)]
                if tot[0]<=0 and turn==0:
                    return False
                
                if tot[0]<=0 and turn!=0:
                    return True
                
                if turn==0:
                    win=False
                    for i in range(vals,0,-1):
                        if can>>i&1==0:
                            tot[0]-=i
                            win|=f(~turn,can^(1<<i))
                            tot[0]+=i
                
                else:
                    win=True
                    for i in range(vals,0,-1):
                        if can>>i&1==0:
                            tot[0]-=i
                            win&=f(~turn,can^(1<<i))
                            tot[0]+=i
                # dp[(turn,can)]=win
                return win
            return f(0,can)
333650