<p>Given a positive integer <code>n</code>, return the number of the integers in the range <code>[0, n]</code> whose binary representations <strong>do not</strong> contain consecutive ones.</p>

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

<pre>
<strong>Input:</strong> n = 5
<strong>Output:</strong> 5
<strong>Explanation:</strong>
Here are the non-negative integers &lt;= 5 with their corresponding binary representations:
0 : 0
1 : 1
2 : 10
3 : 11
4 : 100
5 : 101
Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. 
</pre>

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

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

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

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> 3
</pre>

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

<ul>
	<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>

#define ll long long
#define pb push_back
class Solution {
public:
    ll f(ll index,ll poke,ll tight,vector<vector<vector<ll>>>& dp,string & s,ll n){
        ll sum = 0;
        ll top = s[index]-'0';
        if(dp[index][poke][tight]!=-1)return dp[index][poke][tight];
        if(index==n)return dp[index][poke][tight]=1;
        if(tight==1){
            if(top==0 && poke==0){
                sum+=f(index+1,0,1,dp,s,n);
            }
            else if(top==0 && poke==1){
                sum+=f(index+1,0,1,dp,s,n);
            }
            else if(top==1 && poke==0){
                sum+=f(index+1,1,1,dp,s,n)+f(index+1,0,0,dp,s,n);
            }
            else{
                sum+=f(index+1,0,0,dp,s,n);
            }
        }else{
            if(poke==0){
               sum+=f(index+1,1,0,dp,s,n)+f(index+1,0,0,dp,s,n); 
            }else{
                sum+=f(index+1,0,0,dp,s,n);
            }
        }

        return dp[index][poke][tight]=sum;
    }
    int findIntegers(int n2) {
        string s = "";
        while(n2!=0){
            if(n2%2==0){
                s+='0';
            }else{
                s+='1';
            }
            n2=n2/2;
        }
        reverse(s.begin(),s.end());
        ll n = s.size();
        vector<vector<vector<ll>>>dp(n+1,vector<vector<ll>>(2,vector<ll>(2,-1)));

        ll ans = f(0,0,1,dp,s,n);
        return ans;
    }
};
11300