Round Numbers(数位dp,前导0)

题目链接
题目大意:要求二进制中0的个数大于等于1

#include 
#define ll long long
using namespace std;
int len,dig[40];
ll dp[40][100];
ll dfs(int pos,int state,bool zero,bool limit){
    if(pos==0){
        if(state<=50) return 1;
        return 0;
    }
    if(!limit&&dp[pos][state]!=-1&&!zero) return dp[pos][state];
    int i;
    int up = limit?dig[pos]:9;
    ll ans = 0;
    for(i = 0;i <= up;i ++){
        if(zero&&i==0) {
            ans += dfs(pos-1,state,zero&&i==0,limit&&i==up);
            continue;
        }
        if(i==1) ans += dfs(pos-1,state+1,zero&&i==0,limit&&i==up);
        if(i==0) ans += dfs(pos-1,state-1,zero&&i==0,limit&&i==up);
    }
    if(!limit&&!zero)  dp[pos][state]= ans;
    return ans;
}
ll solve(ll n){
    len = 0;
    while(n!=0){
        dig[++len] = n%2;
        n /= 2;
    }
    return dfs(len,50,1,1);
}
int main()
{
    freopen("a.txt","r",stdin);
    memset(dp,-1,sizeof(dp));
    ll l,r;

    while(cin>>l>>r){
        cout<1)<return 0;
}

你可能感兴趣的:(数位dp)