Editorial for Facebook Hacker Cup '15 Round 2 P2 - All Critical
Submitting an official solution before solving the problem yourself is a bannable offence.
Let be the probability that we have collected exactly
critical bars after
plays of the song. So
, and for
,
. We can then compute
for
and
recursively as follows:
(Note that is the binomial coefficient, or "combinatoric choose" function.)
The intuitive explanation for the above formula is that we want to have exactly critical bars after
playthroughs, and we consider all values
such that we had exactly
critical bars right before our
playthrough. The probability of that having been the case is
, the number of ways to select exactly
of the remaining
sections (on which to get new critical bars) is
, and these values are multiplied by both the probability of getting critical bars on
bars, and by the probability of not getting critical bars on the remaining
bars.
For , let
be the probability that we receive our
critical bar on the
playthrough. For
, we can compute the following:
For example, if there's a chance that we have all of the bars after one playthrough, and a
chance that we have them all after two playthroughs, then there must be a
chance that it will take us exactly two playthroughs to get all of the bars.
We can then compute the expected number of playthroughs, , with the following infinite sum:
Practically though, we only need to evaluate this sum for small values of , up to some value
.
increases linearly, but
falls off exponentially, so their product also decreases exponentially. Since we only need 5 decimal places of precision, it's safe to stop computing the remainder of the sum once this product is reasonably small (say
for example). For the lower bound in this problem,
, giving
a value of
or so is more than sufficient. Computing
for
and
takes on the order of
operations.
Comments