BZOJ4559: [JLoi2016]成绩比较(dp 拉格朗日插值)

题意

题目链接

Sol

想不到想不到。。

首先在不考虑每个人的真是成绩的情况下,设\(f[i][j]\)表示考虑了前\(i\)个人,有\(j\)个人被碾压的方案数

转移方程:$$f[i][j] = \sum_{k = j}^n f[i -1][k] C_{k}^{k - j} C_{N - k}^{r[i] - 1 - (k - j)} * g(i)$$

大概解释一下,枚举的\(k\)表示之前碾压了多少,首先我们凑出\(j\)个人继续碾压,也就是说会有\(k - j\)个人该课的分数比\(B\)爷高,那么这\(k\)个人我们已经考虑完了

接下来需要从剩下的\(N-k\)个人中,选出\(r[i] - 1 - (k - j)\)个人,保证他们的分数比B爷高

后面的\(g(i)\)表示的是吧\(1 \sim U_i\)的分数,分给\(N\)个人后,有\(R_i\)个人比B爷高的方案数

这个计算的时候可以直接枚举B爷的分数

\(g(k) = \sum_{i = 1}^{U_k} i^{N - R[i]} * (U_k - i) ^{R[i] - 1}\)

后面的次数小于等于\(N-1\),然后直接插值一下就行了

// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 103, mod = 1e9 + 7;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int add(int x, int y) {
    if(x + y < 0) return x + y + mod;
    return x + y >= mod ? x + y - mod : x + y;
}
int mul(int x, int y) {
    return 1ll * x * y % mod;
}
int fp(int a, int p) {
    int base = 1;
    while(p) {
        if(p & 1) base = mul(base, a);
        a = mul(a, a); p >>= 1;
    }
    return base;
}
int N, M, K, f[MAXN][MAXN], C[MAXN][MAXN], U[MAXN], R[MAXN], g[MAXN];
int get(int U, int R) {
    memset(g, 0, sizeof(g));
    for(int i = 1; i <= MAXN - 1; i++) 
        for(int k = 1; k <= i; k++) 
            g[i] = add(g[i], mul(fp(k, N - R), fp(i - k, R - 1)));
    int ans = 0;
    for(int i = 1; i <= MAXN - 1; i++) {
        int up = 1, down = 1;
        for(int j = 1; j <= MAXN - 1; j++) {
            if(i == j) continue;
            up = mul(up, add(U, -j));
            down = mul(down, add(i, -j));
        }	
        ans = add(ans, mul(g[i], mul(up, fp(down, mod - 2))));
    }
    return ans;
}
int main() {
    //freopen("a.in", "r", stdin);
    N = read(); M = read(); K = read();
    for(int i = 0; i <= N; i++) {
    	C[i][0] = C[i][i] = 1;
    	for(int j = 1; j < i; j++) C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
    }
    for(int i = 1; i <= M; i++) U[i] = read();
    for(int i = 1; i <= M; i++) R[i] = read();
    f[0][N - 1] = 1;
    for(int i = 1; i <= M; i++) {
    	int t = get(U[i], R[i]);
    	for(int j = K; j <= N; j++) {
    		for(int k = j; k <= N - 1; k++) 
    			if(k - j <= R[i] - 1) f[i][j] = add(f[i][j], mul(mul(f[i - 1][k], C[k][k - j]), C[N - 1 - k][R[i] - 1 - (k - j)]));
    		f[i][j] = mul(f[i][j], t);
    	}
    }
    printf("%d", f[M][K]);
    return 0;
}
/*
100 3 50
500 500 456
13 46 45
*/
posted @ 2018-12-01 21:52  自为风月马前卒  阅读(1284)  评论(2编辑  收藏  举报

Contact with me