Editorial for TLE '17 Contest 3 P4 - Meatballs
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
We will first solve the problem for general , then explain the subtasks.
Let be the probability that the person in line will win if there are people left in line. If , then must be , and by definition, since if there is only one person left, they are declared the winner.
Note that if the person in line survives the round, then in the next round, they are either in position (if somebody behind them was eliminated) or position (somebody ahead of them was eliminated). This suggests that depends on and .
In fact, we can compute the probability that somebody ahead of the person is eliminated by summing the probabilities of being eliminated from persons to . Similarly, we do this for the people behind the person.
There exists a formula for the probability that the person in line is eliminated, which is dependent on , , and . The formula is reasonably easy to compute, so it will not be listed here.
Thus, is equal to multiplied by the probability that somebody ahead of the person is eliminated plus multiplied by the probability that somebody behind the person is eliminated.
For the first subtask, we manually compute the solutions by hand since there are not many of them.
For the second subtask, we perform the dynamic programming without any memoization.
For the third subtask, we perform dynamic programming.
For the fourth subtask, we perform dynamic programming.
For the last subtask, one can make an interesting note about the output from the previous subtasks and conjecture what the solution will be. It will not be posted here, since we don't want people copying this for free. Note however, that the formula can be proven.
Interesting fact: the pretests and samples of this problem all have an output of .
Comments