Editorial for Facebook Hacker Cup '17 Qualifying Round P3 - Fighting the Zombie
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
For each attack, we need to compute the probability that it rolls at least damage. We can compute this using dynamic programming.
Let be the probability of dealing at least damage with dice. For a given input , we want to compute . We can use the following recursive definition:
- for (We can always do at least damage)
- for (We can't do a positive amount of damage with dice)
This last formula combines the outcomes of all possible die rolls for a single die, and weights them evenly by .
In this way, we can compute the probability of success for each attack in time.
Since the most damage we can do is , we can trivially reject any case where . That means we can also consider the time complexity to be .
Comments