其他分享
首页 > 其他分享> > ABC240G Teleporting Takahashi

ABC240G Teleporting Takahashi

作者:互联网

考虑只考虑二维:

\(\sum \binom{x + y + 2k}{x+i,y + k - i,k - i}\\=\sum \binom{x+y+2k}{x+k}\times\binom{x+k}{x+i}\times\binom{y+k}{i}\)

即考虑枚举二维上如何操作,考虑其共走了\(x + y + 2k\)步,

先枚举第一维上的正方向,然后枚举第二维正方向的位置,然后枚举第二维回退的方向位置。

考虑 \(= \binom{x + y + 2k}{x+ k}\times \sum{x+k}{x + i} \times \binom{y + k}{i} = \binom{x + y + 2k}{x + k} \times \binom{x + y + 2k}{x + y + k}\)

那么第三维的处理是简单的。

在化简过程中共使用了\(2\)次范德蒙德卷积

复杂度\(O(n)\)。

点击查看代码
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 10000010, MOD = 998244353;
long long fac[N], inv[N], ans, n, X, Y, Z;
inline long long C (long long n, long long m) {
	if (n < m || n < 0 || m < 0) return 0;
	return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
inline long long solve (long long n, long long m) {
	if (n < m || (n - m) & 1) return 0;
	return C(n, m + (n - m) / 2);
}
int main () {
	scanf("%lld%lld%lld%lld", &n, &X, &Y, &Z);
	fac[0] = fac[1] = inv[1] = inv[0] = 1;
	for (long long i = 2; i <= n; i ++) {
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
	}
	for (long long i = 2; i <= n; i ++)
		inv[i] = inv[i] * inv[i - 1] % MOD;
	for (long long i = 0; i <= n; i ++) {
		long long x = X + Y, y = X - Y;
		ans = (ans + solve(i, x) * solve(i, y) % MOD * C(n, i) % MOD * solve(n - i, Z) % MOD) % MOD;
	}
	printf("%lld", ans);
	return 0;
}

标签:ABC240G,Teleporting,inv,long,times,fac,binom,Takahashi,2k
来源: https://www.cnblogs.com/dixiao/p/16107691.html