[ JLOI 2016 / SHOI 2016 ] 成绩比较

题目

Luogu
LOJ
Acwing

思路

001.png
002.png
003.png
004.png
005.png
006.png

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#define int long long
using namespace std;
const int N = 110, mod = 1e9 + 7;
int n, m, k, T[N], C[N][N], X[N][N], g[N];
int u[N], r[N];
int qmi(int a, int b) {
    int res = 1 % mod;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1) res = res * a % mod;
    return res;
}
int inv(int x) { return qmi(x, mod - 2); }
signed main() {
    cin >> n >> m >> k;
    for (int i = 1; i <= m; i++) cin >> u[i];
    for (int i = 1; i <= m; i++) cin >> r[i];
    for (int i = 0; i <= 100; i++) 
        for (int j = 0; j <= i; j++)
            if (!j) C[i][j] = 1;
            else C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
    for (int i = 1; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            int s = 0;
            for (int t = 0; t <= j - 1; t++) 
                s = (s + C[j + 1][t] * X[i][t] % mod) % mod;
            X[i][j] = ((qmi(u[i] + 1, j + 1) - 1 - s) % mod + mod) % mod *
                       inv(j + 1) % mod;
        }
    }
    for (int i = 1; i <= m; i++) {
        for (int t = 0; t <= r[i] - 1; t++) {
            T[i] = (T[i] + qmi(-1, t) * C[r[i] - 1][t] % mod * 
                    qmi(u[i], r[i] - t - 1) % mod * 
                    X[i][n - r[i] + t] % mod);
        }
    }
    for (int k = 1; k <= n; k++) {
        g[k] = C[n - 1][k];
        for (int i = 1; i <= m; i++) {
            g[k] = g[k] * C[n - 1 - k][n - r[i] - k] % mod * T[i] % mod;
        }
    }
    int res = 0;
    for (int i = k; i <= n; i++)
        res = (res + qmi(-1, i - k) * C[i][k] % mod * g[i] % mod) % mod;
    cout << (res + mod) % mod << endl;
    return 0;
}
posted @ 2021-06-10 21:39  Protein_lzl  阅读(48)  评论(0编辑  收藏  举报