Hello everyone,
in this tutorial we will see a trick that can be useful in combinatorics and/or DP tasks. In particular, you can use it when the statement says something similar to "the score of an array is the product of its elements, find the sum of the scores over all the possible arrays".
Prerequisites: basic combinatorics and DP
The trick
The trick is very simple.
"The score of an array $$$a$$$ is $$$\prod_{i=1}^n a_i$$$" can be rephrased as "if there are $$$n$$$ boxes, and the $$$i$$$-th box contains $$$a_i$$$ distinguishable balls, the score of $$$a$$$ is equal to the number of ways to color a ball for each box".
This is quite obvious, but it can be extremely powerful. Let's see some problems that are trivialized by this trick.
Dwango Programming Contest 6th, problem C (rating: 2618)
abc231_g (rating: 2606)
arc124_e (rating: 3031)
Other problems
No "other problems" yet. You can send them in the comments.
Conclusions
We've seen that "product trick" is very useful to find a DP that solves the problem. There exist similar counting tricks: for example, "The score of an array $$$a$$$ is $$$\sum_{i=1}^n a_i^2$$$" can be rephrased as "if there are $$$n$$$ boxes, and the $$$i$$$-th box contains $$$a_i$$$ distinguishable balls, the score of $$$a$$$ is equal to the number of ordered pairs of balls belonging to the same box" (you can try to use it in 1278F - Карты).
Of course, suggestions/corrections are welcome. In particular, please share in the comments other problems where you can use this trick.
I hope you enjoyed the blog!