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;
    }
    

      

  • 相关阅读:
    XAF 如何在工具栏显示多参数
    XAF Study Recources
    常用工具
    Linux下Kill函数用法
    ipv6相关转换
    宣布回归
    微软夏令营
    APEX SDK阅后感
    寻求offer,开始记录我的征程
    衣服模拟结果
  • 原文地址:https://www.cnblogs.com/rolight/p/3892330.html
Copyright © 2011-2022 走看看