H: Witchwood
https://open.kattis.com/problems/witchwood
Last updated
https://open.kattis.com/problems/witchwood
Last updated
Let be the optimal expected time to build a house with logs. When building a house with logs, we first need to place logs successfully, then place the last log; if the last log fails, then we must start the process over. The probability that the first logs fail does not matter, only the expected time it takes to place them; therefore, we should just choose the strategy with least expected time, i.e. the strategy that takes time in expectation.
Suppose we choose log from location last and let be the overall expected time with this strategy (follow the optimal strategy for the first logs, then choose log as the th). We spend time in expectation to collect the first logs and attempt log , and with probability it fails and forces us to spend an additional in expectation to redo the process. So
and solving
Computationally, we have enough time to check all possible to find the one which minimizes the expected time, so we can write a program that computes