zoukankan      html  css  js  c++  java
  • bzoj3209: 花神的数论题

    数位dp。

    数位dp一直掌握的不好。

    用数位dp求出含若干个1的数的个数。

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #define LL long long 
    using namespace std;
    const LL maxn = 60;
    const LL mod = 10000007;
    LL C[maxn][maxn],a[maxn];
    LL n,res,cnt;
    
    LL power(LL x,LL e) {
        LL res=1;    
        while(e) {
            if(e&1) res=res*x%mod;
            x=x*x%mod;
            e>>=1;
        }
        return res;
    }
    
    LL calc(int x) {
        LL res=0; 
        for(int i=cnt;i && x>=0;i--) 
            if(a[i]) res+=C[i-1][x--];
        return res;
    }
    
    int main() {
        for(int i=0;i<=50;i++) {
            C[i][0]=1;
            for(int j=1;j<=i;j++)
                C[i][j]=C[i-1][j]+C[i-1][j-1];
        }
        scanf("%lld",&n),n++;
        
        while(n) {
            a[++cnt]=n%2;
            n>>=1;    
        }
        
        res=1;
        for(int i=1;i<=cnt;i++) 
            res=res*power(i,calc(i))%mod;
        printf("%lld
    ",res);
        return 0;
    }
  • 相关阅读:
    mysql使用group by查询报错SELECT list is not in GROUP BY clause and contains nonaggregated column...解决方案
    CentOS7 使用minikube 搭建kubernetes 学习环境
    5
    4
    3
    2
    1
    8
    7
    Algorithm
  • 原文地址:https://www.cnblogs.com/invoid/p/5658343.html
Copyright © 2011-2022 走看看