Lust

Lust

转换一下操作,即将\(\prod a_i\)变为\(a_1 *...*a_{x-1} * (a_x - 1) * ... * a_n\),设对第\(i\)个数减了\(b_i\),那么答案就是\(\prod a_i - \prod (a_i - b_i)\)
考虑对于一组\(b_i\),去求\(\prod (a_i - b_i)\)的期望值,满足\(\sum b_i = k\)
那么就为

\[\frac{1}{n^k}*\frac{k!}{\prod b_i!} * \prod (a_i - b_i) = \frac{k!}{n^k} * \prod \frac{a_i - b_i}{b_i!} \]

\(F_x(x) = \sum \frac{a_x - i}{i!} x^i\),那么就为\(\frac{k!}{n^k}*[x^k](\prod F_i(x))\),转化一下\(F\)

\[F = \sum a_x\frac{x^i}{i!} - \sum x \frac{x^{i - 1}}{(i - 1)!} = a_xe^x - xe^x = (a_x - x)e^x \]

所以

\[[x^k]\prod F = [x^k]e^{nx}\prod (a_i - x) = [x^k]e^{nx} \sum^n_i f_ix^i = \sum f_i\frac{n^{k - i}}{(k - i)!} \]

那么答案为\(f_0 - \sum f_i \frac{k^{\underline{i}}}{n^i}\)
暴力求出\(f_i\),计算答案即可,时间复杂度\(O(n^2)\)

Code
#include<cstdio>
#include<iostream>
#define IN inline
#define LL long long
using namespace std;
const int N = 5005, P = 1e9 + 7;
LL n, K, f[N];

IN int read() {
	int t = 0,res = 0; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) t |= (ch == '-');
	for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
	return t ? -res : res;
}
LL fpow(LL x, LL y) {
	LL res = 1;
	for (; x; x >>= 1, y = y * y % P)
		if (x & 1) res = res * y % P;
	return res;
}
int main() {
	n = read(), K = read(), f[0] = 1;
	for (int i = 1; i <= n; i++) {
		LL a = read(); 
		for (int j = i; j >= 1; j--) f[j] = (f[j] * a % P - f[j - 1] + P) % P; 
		f[0] = f[0] * a % P;
	}
	LL ans = f[0], sum = 1, pw = 1, invn = fpow(P - 2, n);
	for (int i = 0; i <= (n < K ? n : K); i++)
		(ans += P - f[i] * sum % P * pw % P) %= P, sum = sum * (K - i) % P, pw = pw * invn % P;
	printf("%lld\n", ans);
}

posted @ 2023-03-15 21:55  RiverSheep  阅读(58)  评论(0编辑  收藏  举报