G - Balls in Boxes Editorial by Kiri8128


Let a polynomial \(x_1^{c_1}\cdots x_N^{c_N}\) denote the state where each of the box \(i\) has \(c_i\) balls in it. One operation is equivalent to multiplying the polynomial \(\displaystyle\frac{1}{N}(x_1 + x_2 + \cdots + x_{N})\) , where the coefficient \(\displaystyle\frac{1}{N}\) is a weight by the probability. The score of a state can be calculated as follows: partially differentiate the polynomial by \(x_i\) for all \(i\) in \(1\) to \(N\), inclusive, then substitute \(1\) for all \(x_i\). Let \(y=x_1 + x_2 + \cdots + x_{N}\) . The state after \(K\) operations is shown as \(f=\displaystyle\frac{1}{N^K}\left(\displaystyle\prod_{i=1}^{N} x_i^{a_i}\right)\cdot y^K\) . We want to calculate \(g=\displaystyle\frac{\partial^N}{\partial x_1\cdots\partial x_N} f\) . Note that \(\displaystyle\frac{\partial}{\partial x_i}f=\left(\displaystyle\frac{a_i}{x_i}+\frac{\partial}{\partial y}\right) f\) for polynomials with the form of \(f\). With this, we can expand \(\displaystyle\frac{\partial^N}{\partial x_1\cdots\partial x_N} =\left(\displaystyle\frac{a_1}{x_1}+\frac{\partial}{\partial y}\right)\cdots \left(\displaystyle\frac{a_N}{x_N}+\frac{\partial}{\partial y}\right)\) as the coefficients of this formula are same as \((a_1+X)\cdots(a_N+X)\), which can be calculated in \(O(N^2)\) time with a naive calculation, or \(O(N(\log N)^2)\) with FFT.

posted:
last update: