CF1716F

CF932ECF1278F 其实差不多捏。

首先 \(m\) 中奇数个数是 \(\left\lceil\frac{m}{2}\right\rceil\),偶数个数是 \(\left\lfloor\frac{m}{2}\right\rfloor\)。下文为了方便记 \(p=\left\lceil\frac{m}{2}\right\rceil,q=\left\lfloor\frac{m}{2}\right\rfloor\)

考虑先写出暴力的式子,枚举取奇数的盒子个数:

\[\sum_{i=1}^{n}\binom{n}{i}p^iq^{n-i}i^k \]

依旧把 \(i^k\) 展开:

\[=\sum_{i=1}^{n}\binom{n}{i}p^iq^{n-i}\sum_{j=1}^{k}\begin{Bmatrix}k\\ j\end{Bmatrix}j!\binom{i}{j} \]

\[=\sum_{j=1}^{k}\begin{Bmatrix}k\\ j\end{Bmatrix}j!\sum_{i=1}^{n}\binom{n}{i}\binom{i}{j}p^iq^{n-i} \]

\[=\sum_{j=1}^{k}\begin{Bmatrix}k\\ j\end{Bmatrix}j!\binom{n}{j}\sum_{i=j}^{n}\binom{n-j}{i-j}p^iq^{n-i} \]

\[=\sum_{j=1}^{k}\begin{Bmatrix}k\\ j\end{Bmatrix}n^{\underline{j}}\sum_{i=0}^{n-j}\binom{n-j}{i}p^{i+j}q^{n-j-i} \]

\[=\sum_{j=1}^{k}\begin{Bmatrix}k\\ j\end{Bmatrix}n^{\underline{j}}p^j\sum_{i=0}^{n-j}\binom{n-j}{i}p^{i}q^{n-j-i} \]

\[=\sum_{j=1}^{k}\begin{Bmatrix}k\\ j\end{Bmatrix}n^{\underline{j}}p^j(p+q)^{n-j} \]

\[=\sum_{j=1}^{k}\begin{Bmatrix}k\\ j\end{Bmatrix}n^{\underline{j}}p^jm^{n-j} \]

然后 \(\mathcal O(k^2)\) 预处理斯特林数啥的就好了。

Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2005, mod = 998244353;
int T;
int n, m, k;
int S[N][N], f[N];

int qpow(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;
		y >>= 1;
	}
	return res;
}

void init(int n) {
	S[0][0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= i; ++j)
			S[i][j] = (S[i - 1][j - 1] + 1ll * S[i - 1][j] * j % mod) % mod;
}

void solve() {
	scanf("%d%d%d", &n, &m, &k);
	f[0] = 1;
	for (int i = 1; i <= min(n, k); ++i) f[i] = 1ll * f[i - 1] * (n - i + 1) % mod;
	int cnt = (m + 1) / 2;
	int ans = 0;
	int x = cnt, y = qpow(m, n - 1), invm = qpow(m, mod - 2);
	for (int i = 1; i <= min(n, k); ++i) {
		int tmp = 1ll * S[k][i] * f[i] % mod * x % mod * y % mod;
		ans = (ans + tmp) % mod, x = 1ll * x * cnt % mod, y = 1ll * y * invm % mod;
	}
	printf("%d\n", ans);
}

int main() {
	init(2000);
	scanf("%d", &T);
	while (T--) solve();
	return 0;
}
posted @ 2022-10-25 08:13  Kobe303  阅读(13)  评论(0编辑  收藏  举报