其他分享
首页 > 其他分享> > GYM 101933K(二项式反演、排列组合)

GYM 101933K(二项式反演、排列组合)

作者:互联网

要点

#include <cstdio>

const int mod = 1e9 + 7;
int n, k, ans;
int C[2505][2505], f[2505];

int ksm(int a, int b) {
    int res = 1;
    for (; b; b >>= 1) {
        if (b & 1)  res = 1LL * res * a % mod;
        a = 1LL * a * a % mod;
    }
    return res;
}

void Pre() {
    for (int i = 0; i <= k; i++) {
        f[i] = 1LL * i * ksm(i - 1, n - 1) % mod;
        C[i][i] = C[i][0] = 1;
        for (int j = 1; j < i; j++) {
            C[i][j] = (1LL * C[i - 1][j] + C[i - 1][j - 1]) % mod;
        }
    }
}

int main() {
    scanf("%d %d", &n, &k);
    for (int i = 1, x; i < n; i++)
        scanf("%d", &x);
    Pre();
    
    for (int i = 0; i <= k; i++) {
        int a = (k - i) % 2 ? -1 : 1;
        int tmp = (1LL * a * C[k][i] % mod * f[i] % mod + mod) % mod;
        ans = (ans + tmp) % mod;
    }
    return !printf("%d\n", ans);
}

标签:int,res,GYM,反演,101933K,涂色,2505,mod
来源: https://www.cnblogs.com/AlphaWA/p/10851266.html