ABC240G Teleporting Takahashi
洛谷:ABC240G Teleporting Takahashi
Atcoder:ABC240G Teleporting Takahashi
Problem
在一个空间直角坐标系中移动,每步可以沿着坐标轴正/负方向移动一个单位的长度。
给定 \(N,X,Y,Z\) ,求:
恰好 \(N\) 步,从点 \((0,0,0)\) 走到点 \((X,Y,Z)\) 的方案数。
答案对 \(998244353\) 取模。\(N,X,Y,Z \le 10^7\)。s
Solution
先把答案为 \(0\) 判掉。
记 \(w = \frac{n - x - y - z}{2}\)。
答案为:
\[\sum\limits_{a_1 + a_2 + a_3 = w}\binom{x + 2a_1}{a_1}\binom{y + 2a_2}{a_2}\binom{z + 2a_3}{a_3}\binom{n}{x + 2a_1}\binom{n - x - 2a_1}{y + 2a_2} \]然后化简。拆开消项以组成新的二项式系数。
\[\begin{aligned} ans &= \sum\limits_{a_1 + a_2 + a_3 = w}\binom{x + 2a_1}{a_1}\binom{y + 2a_2}{a_2}\binom{z + 2a_3}{a_3}\binom{n}{x + 2a_1}\binom{n - x - 2a_1}{y + 2a_2} \\ &= \sum\limits_{a_1 + a_2 = 0}^{w}\binom{x + 2a_1}{a_1}\binom{y + 2a_2}{a_2}\binom{z + 2(w - a_1 - a_2)}{w - a_1 - a_2}\binom{n}{x + 2a_1}\binom{n - x - 2a_1}{y + 2a_2} \\ &= \sum\limits_{S = 0}^{w}\sum\limits_{a_1 = 0}^{S}\binom{x + 2a_1}{a_1}\binom{y + 2S - 2a_1}{S - a_1}\binom{z + 2w - 2S}{w - S}\binom{n}{x + 2a_1}\binom{n - x - 2a_1}{y + 2S - 2a_1} \\ &= \sum\limits_{S = 0}^{w}\binom{z + 2w - 2S}{w - S}\sum\limits_{a_1 = 0}^{S}\binom{x + 2a_1}{a_1}\binom{y + 2S - 2a_1}{S - a_1}\binom{n}{x + 2a_1}\binom{n - x - 2a_1}{y + 2S - 2a_1} \\ \end{aligned} \]记 \(W = \sum\limits_{a_1 = 0}^{S}\binom{x + 2a_1}{a_1}\binom{y + 2S - 2a_1}{S - a_1}\binom{n}{x + 2a_1}\binom{n - x - 2a_1}{y + 2S - 2a_1}\)。
\[\begin{aligned} W &= \sum\limits_{a_1 = 0}^{S}\binom{x + 2a_1}{a_1}\binom{y + 2S - 2a_1}{S - a_1}\binom{n}{x + 2a_1}\binom{n - x - 2a_1}{y + 2S - 2a_1} \\ &= \sum\limits_{a_1 = 0}^{S} \frac{(x + 2a_1)!}{a_1!(x + a_1)!}\frac{(y + 2S - 2a_1)!}{(S - a_1)!(y + S - a_1)!}\frac{n!}{(x + 2a_1)!(n - x - 2a_1)!}\frac{(n - x - 2a_1)!}{(y + 2S - 2a_1)!(n - x - y - 2S)!} \\ &= \sum\limits_{a_1 = 0}^{S}\frac{n!}{a_1!(x + a_1)!(S - a_1)!(y + S - a_1)!(n - x - y - 2S)!} \\ &= n! \times \frac{1}{S!} \times \frac{1}{(x + y + S)!} \times \frac{1}{(n - x - y - 2S)!} \sum\limits_{a_1 = 0}^{S} \frac{S!}{a_1!(S - a_1)!}\frac{(x + y + S)!}{(x + a_1)!(y + S - a_1)!} \\ &= \frac{n!}{S!(x + y + S)!(n - x - y - 2S)!}\sum\limits_{a_1 = 0}^{S}\binom{S}{a_1}\binom{x + y + S}{y + S - a_1} \\ &= \frac{n!}{S!(x + y + S)!(n - x - y - 2S)!} \binom{x + y + 2S}{y + S} \end{aligned} \]于是可以枚举 \(S\)。
code ABC240G Teleporting Takahashi
标签:ABC240G,Teleporting,limits,2S,sum,2a,frac,binom,Takahashi From: https://www.cnblogs.com/Schucking-Sattin/p/17136911.html