<p>Given an integer <code>n</code>, return the count of all numbers with unique digits, <code>x</code>, where <code>0 &lt;= x &lt; 10<sup>n</sup></code>.</p>

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

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> 91
<strong>Explanation:</strong> The answer should be the total numbers in the range of 0 &le; x &lt; 100, excluding 11,22,33,44,55,66,77,88,99
</pre>

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

<pre>
<strong>Input:</strong> n = 0
<strong>Output:</strong> 1
</pre>

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

<ul>
	<li><code>0 &lt;= n &lt;= 8</code></li>
</ul>

class Solution {
public:
    string l,r;
    int len;
    int dp[10][2][2][(1<<10)];
    int rec(int lev, int lt, int rt, int mask){
        if(lev==len)return 1;
        if(dp[lev][lt][rt][mask]!=-1)return dp[lev][lt][rt][mask];
        int lo=(lt?l[lev]-'0' : 0), hi=(rt?r[lev]-'0' : 9),ans=0;
        for(int i=lo;i<=hi;i++){
            if((mask)&(1<<i))continue;
            int nlt=(lt&&(i==lo)),nrt=(rt&&(i==hi));
            if(mask==0 && i==0)ans+=rec(lev+1,nlt,nrt,mask);
            else ans+=rec(lev+1,nlt,nrt,mask|(1<<i));
        }
        return dp[lev][lt][rt][mask]=ans;
    }
    int countNumbersWithUniqueDigits(int n) {
        int num = pow(10,n);
        //cout<<num<<endl;
        r=to_string(num-1);
        len=r.length();
        for(int i=0;i<len;i++)l.push_back('0');
        cout<<l<<" "<<r;
        memset(dp,-1,sizeof(dp));
        return rec(0,1,1,0);
    }
};
7800