Team work [2018] Repeater

Even a dish question, also can not cover up the fact that weak nest generation function.

Waterloo see only think of the subject DP, or generating functions cooked enough. Until then WWJ reminded me immortal with a generating function ......

The first is the arrangement, it can be written in the form of a beautiful exponential generating function. It is directly expressed as exp, and d on the multiple processing units to the root properties.

So actually seeking \ ([x ^ n] ( \ frac {\ sum_ {i = 0} ^ {D - 1} e ^ {\ omega_ {D} ^ {i} x}} {D}) ^ K \)

Obviously you can put under the \ (D ^ K \) proposed, this time seeking the things above.

How seeking first \ (n \) coefficient ah?

This time can be found in \ (D \) big time \ (K \) small (and then look at a range was last pit)

So violence can be found binomial expansion!

Enumeration \ (I \) the number of times a unit root complexity \ (O (D K ^ {-}. 1) \) ,

Then the rest of it according to the nature of the exponential function may be combined into one \ (E Cx ^ {} \) , but this time the coefficient a fast power thing.

Unit root of things casually seeking a better throw up.

#include <bits/stdc++.h>

const int mod = 19491001;
const int MAXN = 500010;
typedef long long LL;
int mul(int a, int b) { return (LL) a * b % mod; }
void reduce(int & x) { x += x >> 31 & mod; }
int fastpow(int a, int b) {
    int res = 1;
    for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
    return res;
}
int n, K, D, fac[MAXN], inv[MAXN];
int C(int a, int b) { return (LL) fac[a] * inv[b] % mod * inv[a - b] % mod; }
int pr[3], ans;
void dfs(int S, int rest, int sum, int way) {
    if (S == D - 1) {
        reduce(sum += mul(pr[S], rest) - mod);
        reduce(ans += mul(fastpow(sum, n), way) - mod);
        return ;
    }
    for (int i = 0; i <= rest; ++i)
        dfs(S + 1, rest - i, (sum + (LL) pr[S] * i) % mod, mul(way, C(rest, i)));
}
int main() {
    std::cin >> n >> K >> D;
    fac[0] = fac[1] = inv[0] = inv[1] = 1;
    for (int i = 2; i <= K; ++i) {
        fac[i] = mul(fac[i - 1], i);
        inv[i] = mul(inv[mod % i], mod - mod / i);
    }
    for (int i = 2; i <= K; ++i)
        inv[i] = mul(inv[i - 1], inv[i]);
    pr[0] = 1;
    if (D == 2) pr[1] = mod - 1;
    if (D == 3) pr[1] = 663067, pr[2] = mul(pr[1], pr[1]);
    dfs(0, K, 0, 1);
    ans = mul(ans, fastpow(D, mod - 1 - K));
    std::cout << ans << std::endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/daklqw/p/11588389.html