Official
D - I Wanna Win The Game Editorial by evima Editorial for printing
If we consider the lowest bit and the other bits separately, “the other bits” can be reduced to the same problem with a smaller input. More specifically, let:
\(dp_i =\) the number of non-negative integers totaling \(i\) whose \(xor\) is \(0\)
Then, we have the following recurrence relation:
\[dp_i = \begin{cases} \sum_{j} \binom{N}{2*j}dp_{\left(i - 2j\right) / 2} & \text{if }i\text{ is even} \\ 0 & \text{if }i\text{ is odd} \end{cases} \]
By filling the DP table in ascending order according to this recurrence relation, we can solve the problem in \(O(M^2)\) time, excluding the precomputation for binomial coefficients.
posted:
last update: