Editorial for DMOPC '14 Contest 2 P5 - Sawmill Scheme


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.

This is a graph theory problem. The graph is a DAG (Directed Acyclic Graph) and we can use dynamic programming to find probabilities.

dp[i] is the probability of a log floating to lake i. In the edge from i to j, we will call j the child of i. For each child of i, add \dfrac{dp[i]}{\text{total rivers leading out}} to its probability (dp[j]), as we have an equal probability of selecting a river to flow to.

At the end, output the value for all lakes which have no children. Be careful to output at least 9 digits. Fast input and output methods should be used if possible.


Comments

There are no comments at the moment.