Codeforces 747F Igor and Interesting Numbers dp

Posted cjlhy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 747F Igor and Interesting Numbers dp相关的知识,希望对你有一定的参考价值。

Igor and Interesting Numbers

枚举每一位, 用dp去算方案数。

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);

using namespace std;

const int N = 20 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);

template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}

LL F[18];
LL dp[16][18];

int c[16];
int ans[17];

int k, t;

LL getDp(int n, int *c) {
    if(n == 0) return 1;
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i <= c[0]; i++) dp[0][i] = 1;
    for(int i = 0; i < 15; i++) {
        for(int j = 0; j <= n; j++) {
            for(int k = 0; k <= c[i + 1]; k++) {
                if(j + k > n) continue;
                dp[i + 1][j + k] += F[j + k] / F[j] / F[k] * dp[i][j];
            }
        }
    }
    return dp[15][n];
}

char print(int x) {
    if(x <= 9) return 0 + x;
    else return a + (x - 10);
}

int main() {
    for(int i = F[0] = 1; i <= 17; i++) F[i] = F[i - 1] * i;
    scanf("%d%d", &k, &t);
    for(int i = 0; i <= 15; i++) c[i] = t;
    for(int len = 1; len <= 17; len++) {
        LL tot = 0;
        for(int j = 1; j <= 15; j++) {
            if(!c[j]) continue;
            c[j]--;
            int way = getDp(len - 1, c);
            if(way < k) k -= way, c[j]++, tot += way;
            else {
                ans[1] = j;
                break;
            }
        }
        if(!ans[1]) continue;
        for(int i = 2; i <= len; i++) {
            for(int j = 0; j <= 15; j++) {
                if(!c[j]) continue;
                c[j]--;
                int way = getDp(len - i, c);
                if(way < k) k -= way, c[j]++;
                else {
                    ans[i] = j;
                    break;
                }
            }
        }
        for(int i = 1; i <= len; i++) printf("%c", print(ans[i]));
        puts("");
        return 0;
    }
    return 0;
}

/*
*/

 

以上是关于Codeforces 747F Igor and Interesting Numbers dp的主要内容,如果未能解决你的问题,请参考以下文章

[CF 747F]Igor and Interesting Numbers

codeforces 793B - Igor and his way to work(dfsbfs)

Codeforces Round #387 (Div. 2) 747F(数位DP)

CS294-112 深度强化学习 秋季学期(伯克利)NO.19 Guest lecture: Igor Mordatch (Optimization and Reinforcement Learnin

Igor绘制雷达图

CodeForces 621AWet Shark and Odd and Even