其他分享
首页 > 其他分享> > [题解][YZOJ7249]Curiosity

[题解][YZOJ7249]Curiosity

作者:互联网

简要题意

一个 \(K\) 面骰子扔 \(N\) 次,记 \(i\) 的出现次数为 \(a_i\),求:

\[E[\ \prod_{i=1}^La_i^F\ ] \]

\(0<N,K\le 10^9,0<F\le 1000,0<L\cdot F\le 50000,1\le L\le K\).

解题思路

首先不难写出单个数贡献的生成函数 \(A(x)=\sum\dfrac{i^Fx^i}{i!}\),那么前 \(L\) 个数贡献的生成函数就是 \(F(x)=A^L(x)\),于是不难得出最终答案可以表示为:

\[\frac{1}{K^N}\sum_{i=0}^N[x^i]F(x)\cdot i!\cdot \binom{N}{i}\cdot(K-L)^{N-i} \]

接下来就是一堆化式子,首先来将 \(A\) 化成一个更常见的形式,考虑到 \(\sum\dfrac{x^i}{i!}=e^x\),所以试图把 \(i^F\) 处理掉,那么不妨尝试化成下降幂看看,即 \(n^m=\sum\limits_{i=0}^m\begin{Bmatrix}m\\i\end{Bmatrix}n^{\underline{i}}\),那么就有:

\[\begin{aligned} \sum_{i\ge0}\frac{i^Fx^i}{i!} &=\sum_{i\ge0}\frac{x^i}{i!}\sum_{d=0}^F\begin{Bmatrix}F\\d\end{Bmatrix}i^{\underline{d}}\\ &=\sum_{i\ge0}\frac{x^i}{i!}\sum_{d=0}^F\begin{Bmatrix}F\\d\end{Bmatrix}\frac{i!}{(i-d)!}\\ &=\sum_{d=0}^F\begin{Bmatrix}F\\d\end{Bmatrix}\sum_{i\ge d}\frac{x^i}{(i-d)!}\\ &=\sum_{d=0}^F\begin{Bmatrix}F\\d\end{Bmatrix}x^d\sum_{i\ge d}\frac{x^{i-d}}{(i-d)!}\\ &=\sum_{d=0}^F\begin{Bmatrix}F\\d\end{Bmatrix}x^de^x\\ \end{aligned} \]

于是 \(F(x)\) 就有了更加简单的一个形式:

\[\begin{aligned} F(x)&=(\sum_{d=0}^F\begin{Bmatrix}F\\d\end{Bmatrix}x^d)^L(e^x)^L\\ &=(\sum_{d=0}^F\begin{Bmatrix}F\\d\end{Bmatrix}x^d)^L\cdot e^{xL}\\ &=(\sum_{d=0}^F\begin{Bmatrix}F\\d\end{Bmatrix}x^d)^L\cdot (\sum_{i\ge 0}\frac{L^i}{i!}x^i)\\ \end{aligned} \]

因为前面一部分的次数 \(L\cdot F\le 5000\),不妨直接展开得到每一项的系数,记为 \(g(d)\),然后重新表示答案:

\[\frac{1}{K^N}\sum_{d=0}^{LF}g(d)\sum_{i=d}^N\frac{L^{i-d}}{(i-d)!}\cdot i!\cdot \binom{N}{i}\cdot(K-L)^{N-i} \]

尝试整理后面求和的一堆东西:

\[\begin{aligned} &\sum_{i=d}^N\frac{L^{i-d}}{(i-d)!}\cdot i!\cdot \binom{N}{i}\cdot(K-L)^{N-i}\\ =&d!\sum_{i=d}^N\frac{i!}{d!(i-d)!}\binom{N}{i}\cdot(K-L)^{N-i}\cdot L^{i-d}\\ =&d!\sum_{i=d}^N\binom{N}{i}\binom{i}{d}\cdot(K-L)^{N-i}\cdot L^{i-d}\\ =&d!\sum_{i=d}^N\binom{N}{d}\binom{N-d}{i-d}\cdot(K-L)^{N-i}\cdot L^{i-d}\\ =&d!\cdot\binom{N}{d}\cdot K^{N-d} \end{aligned} \]

于是这个题就做完啦:

\[\frac{1}{K^N}\sum_{d=0}^{LF}g(d)\cdot d!\cdot \binom{N}{d}\cdot K^{N-d} \]

代码

void solve(){
	cin >> N >> K >> L >> F;
	
	int pw = L, LF = L * F, len = 1; while(len <= LF) len <<= 1; 
	lep(i, 0, len) a[i] = g[i] = 0;
	
	g[0] = 1;
	lfor(i, 0, F) a[i] = S[F][i]; FFT(a, len, 1);
	
	while(pw){
		if(pw & 1){
			FFT(g, len, 1); lep(i, 0, len) g[i] = g[i] * a[i];
			FFT(g, len, -1);
			lfor(i, 0, LF) g[i] = g[i].Int();
			lep(i, LF + 1, len) g[i] = 0;
		}
		lep(i, 0, len) a[i] = a[i] * a[i]; FFT(a, len, -1); 
		lfor(i, 0, LF) a[i] = a[i].Int();
		lep(i, LF + 1, len) a[i] = 0; FFT(a, len, 1);
		pw >>= 1;
	}
	
	int Ans = 0;
	lfor(d, 0, min({N, LF, mod - 1})){
		int sum = g[d].Int() * fac[d] % mod;
		sum = sum * C(N, d) % mod * qpow(K, N - d) % mod;
		MOD(Ans += sum - mod);
	}
	Ans = Ans * qpow(qpow(K), N) % mod;
	cout << Ans << endl;
}

标签:begin,frac,Curiosity,cdot,题解,sum,YZOJ7249,Bmatrix,end
来源: https://www.cnblogs.com/Callis/p/16434151.html