zoukankan      html  css  js  c++  java
  • poj3252数位dp

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <climits>
    #include <string>
    #include <iostream>
    #include <map>
    #include <cstdlib>
    #include <list>
    #include <set>
    #include <queue>
    #include <stack>
    #include<math.h>
    using namespace std;
    int dp[55][55][55];
    int up[100];
    int dfs(int now,int len0,int len1,int flag)
    {
        if(now==-1) return len0>=len1;
        if(!flag&&dp[now][len0][len1]!=-1) return dp[now][len0][len1];
        int limit= flag?up[now ]:1 ,ret=0 ;
        for(int i = 0;i <= limit;i++){
            int len00=len0;int len11=len1;
            if(i==0&&len1) len00=len0+1;
            if(i==1) len11=len1+1;
            ret+=dfs(now-1,len00,len11,flag&&i==limit) ;
        }
        if(!flag) dp[now][len0][len1]=ret;
        return ret;
    }
    int solve(int x)
    {
        int len=-1;
        while(x){
            up[++len]=x%2;
            x/=2;
        }
        return dfs(len,0,0,1);
    }
    int main()
    {
        int n, m;
        memset(dp,-1,sizeof(dp));
        while(cin>>n>>m){
            cout<<solve(m) - solve(n-1)<<endl;
        }
        return 0;
    }
  • 相关阅读:
    python 函数嵌套
    python 函数对象
    python 函数参数
    python 连接MySQL报错及解决方案
    解决 No module named pip
    python 文件处理
    python
    python 元祖
    python 读取域名信息
    ubuntu 配置网卡,DNS, iptables
  • 原文地址:https://www.cnblogs.com/yigexigua/p/3896114.html
Copyright © 2011-2022 走看看