Editorial for COCI '22 Contest 4 #3 Bojanje
Submitting an official solution before solving the problem yourself is a bannable offence.
To solve the first subtask, notice that, in order to not decrease the number of different colours, Oliver has to choose the same part of the painting in both steps. The probability that this will happen is per iteration, and after iterations.
The second subtask can be solved by using dynamic programming. The states will be all partitions of the number (sorted array of frequencies of each of the colours) because the symmetrical cases when we rotate the frequencies of each colour are redundant. Now we go through all combinations of Oliver's choice of two parts and determine in which partition of it will change into. This is the transition. We will repeat it times and then sum up all probabilities of partitions that consist of at least colours.
For solving the last subtask, it is necessary to notice that we are using always the same transition, and that, actually, each of the elements from the current state is a linear combination of elements from the previous states. Because of that, we can store the states in a mathematical vector and create a transition matrix, and then apply the matrix times.
Comments