Bzoj4555: [Tjoi2016&Heoi2016]求和

Posted Cyhlnj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Bzoj4555: [Tjoi2016&Heoi2016]求和相关的知识,希望对你有一定的参考价值。

题面

Bzoj

Sol

推柿子
因为当\\(j>i\\)\\(S(i, j)=0\\),所以有

\\[\\sum_{i=0}^{n}\\sum_{j=0}^{n}S(i, j)2^j(j!) \\]

枚举\\(j\\)

\\[\\sum_{j=0}^{n}2^j(j!)\\sum_{i=0}^{n}S(i, j) \\]

带入\\(S(i, j)\\)公式

\\[\\sum_{j=0}^{n}2^j(j!)\\sum_{i=0}^{n}\\sum_{k=0}^{j}\\frac{(-1)^k}{k!}\\frac{(j-k)^i}{(j-k)!} \\]

\\[=\\sum_{j=0}^{n}2^j(j!)\\sum_{k=0}^{j}\\frac{(-1)^k}{k!}\\frac{\\sum_{i=0}^{n}(j-k)^i}{(j-k)!} \\]

\\(\\sum_{i=0}^{n}(j-k)^i\\)有公式求,然后跑\\(NTT\\)

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int Zsy(998244353);
const int _(4e5 + 5);
const int Phi(998244352);
const int G(3);

IL int Input(){
    RG int x = 0, z = 1; RG char c = getchar();
    for(; c < \'0\' || c > \'9\'; c = getchar()) z = c == \'-\' ? -1 : 1;
    for(; c >= \'0\' && c <= \'9\'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * z;
}

int n, A[_], B[_], N, l, r[_], fac[_], inv[_], mul[_], pw[_], ans;

IL int Pow(RG ll x, RG ll y){
    RG ll ret = 1;
    for(; y; y >>= 1, x = x * x % Zsy) if(y & 1) ret = ret * x % Zsy;
    return ret;
}

IL void NTT(RG int* P, RG int opt){
    for(RG int i = 0; i < N; ++i) if(i < r[i]) swap(P[i], P[r[i]]);
    for(RG int i = 1; i < N; i <<= 1){
        RG int W = Pow(G, Phi / (i << 1));
        if(opt == -1) W = Pow(W, Zsy - 2);
        for(RG int p = i << 1, j = 0; j < N; j += p)
            for(RG int w = 1, k = 0; k < i; ++k, w = 1LL * w * W % Zsy){
                RG int X = P[k + j], Y = 1LL * w * P[k + j + i] % Zsy;
                P[k + j] = (X + Y) % Zsy, P[k + j + i] = (X - Y + Zsy) % Zsy;
            }
    }
    if(opt == 1) return;
    RG int Inv = Pow(N, Zsy - 2);
    for(RG int i = 0; i < N; ++i) P[i] = 1LL * P[i] * Inv % Zsy;
}

IL void Mul(){
    for(N = 1; N <= n + n; N <<= 1) ++l;
    for(RG int i = 0; i < N; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
    NTT(A, 1); NTT(B, 1);
    for(RG int i = 0; i < N; ++i) A[i] = 1LL * A[i] * B[i] % Zsy;
    NTT(A, -1);
}

int main(RG int argc, RG char* argv[]){
    n = Input(), pw[0] = fac[0] = mul[0] = 1, mul[1] = n + 1;
    for(RG int i = 1; i <= n; ++i){
        fac[i] = 1LL * i * fac[i - 1] % Zsy;
        pw[i] = 1LL * 2 * pw[i - 1] % Zsy;
        if(i == 1) continue;
        mul[i] = 1LL * (Pow(i, n + 1) - 1) * Pow(i - 1, Zsy - 2) % Zsy;
        if(mul[i] < 0) mul[i] += Zsy;
    }
    inv[n] = Pow(fac[n], Zsy - 2);
    for(RG int i = n - 1; ~i; --i) inv[i] = 1LL * inv[i + 1] * (i + 1) % Zsy;
    for(RG int i = 0; i <= n; ++i){
        A[i] = B[i] = inv[i];
        if(i & 1) A[i] = Zsy - A[i];
        B[i] = 1LL * mul[i] * inv[i] % Zsy;
    }
    Mul();
    for(RG int i = 0; i <= n; ++i) (ans += 1LL * A[i] * pw[i] % Zsy * fac[i] % Zsy) %= Zsy;
    printf("%d\\n", ans);
    return 0;
}

以上是关于Bzoj4555: [Tjoi2016&Heoi2016]求和的主要内容,如果未能解决你的问题,请参考以下文章

Bzoj4555: [Tjoi2016&Heoi2016]求和

BZOJ4555: [Tjoi2016&Heoi2016]求和

bzoj4555 [Tjoi2016&Heoi2016]求和

BZOJ4555: [Tjoi2016&Heoi2016]求和

[bzoj4555] [Tjoi2016&Heoi2016]求和

bzoj4555 [Tjoi2016&Heoi2016]求和