zoukankan      html  css  js  c++  java
  • URAL 1057 Amount of Degrees 数位DP

    水题,随便统计一下就好

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <string>
    #include <iostream>
    #include <map>
    #include <cstdlib>
    #include <list>
    #include <set>
    #include <queue>
    #include <stack>
    
    using namespace std;
    
    typedef long long LL;
    const int maxn = 100;
    int lim[maxn],B,K,len;
    int f[maxn][maxn];
    
    void getlim(int num) {
        len = 0; memset(lim,0,sizeof(lim));
        while(num) {
            lim[len++] = num % B;
            num /= B;
        }
    }
    
    int dfs(int now,int cnt,int bound) {
        if(now == 0) {
            return cnt == K;
        }
        int ret = 0,m = bound ? lim[now - 1] : 1;
        int &note = f[now][cnt];
        if(!bound && note != -1) return note;
        for(int i = 0;i <= m;i++) {
            if(i == 0) ret += dfs(now - 1,cnt,bound && i == m);
            else if(i == 1) {
                if(cnt == K) continue;
                ret += dfs(now - 1,cnt + 1,bound && i == m);
            }
        }
        if(!bound) note = ret;
        return ret;
    }
    
    int solve(int num) {
        getlim(num);
        memset(f,-1,sizeof(f));
        return dfs(len,0,1);
    }
    
    
    int main() {
        int X,Y;
        cin >> X >> Y >> K >> B;
        cout << solve(Y) - solve(X - 1) << endl;
        return 0;
    }
    

      

  • 相关阅读:
    第四章
    第三章
    第二章
    实验5-2: 编制程序,输入m、n(m≥n≥0)后,计算下列表达式的值并输出。 要求将计算阶乘的运算编写作函数fact(n),函数返回值的类型为float
    作业
    多人电费
    单人电费
    圆柱体积
    圆面积
    第七章
  • 原文地址:https://www.cnblogs.com/rolight/p/3892330.html
Copyright © 2011-2022 走看看