Problem F
Pegs and Legs
Pegs and Legs is a game where a disk slides down a nearly-vertical board. At the bottom of the board are places for the disk to land, called legs. Each leg is worth a certain amount of points if your disk lands in it.
You start with a disk at the top and drop it onto some
drop point peg or directly into some
drop point leg. When your disk hits a
peg, one of three things happen: (1) the disk falls to the left
with probability
![\includegraphics[width=0.5\textwidth ]{pegsandlegs.pdf}](/problems/pegsandlegs/file/statement/en/img-0001.png)
Because of gravity it is not possible for a disk to hit the same peg more than once unless the disk is dropped again. The game continues until your disk lands in a leg, at which point you earn the value of that leg. What is the maximum possible expected score the player can earn?
Input
The first line of input contains two integers
The next
The next
All real numbers are specified to exactly 3 decimal places. A peg or leg is a drop point if there are no pegs that drop into this peg or leg.
It is guaranteed that from any peg (whether a drop point or
not), the probability the disk eventually gets stuck after
reaching this peg is at most
Output
Display the maximum possible expected score the player can
earn. Answers with an absolute error or relative error of at
most
Sample Input 1 | Sample Output 1 |
---|---|
2 4 344969 539194 0.508 0.318 1 1 0.990 0.009 1 3 0.807 0.041 3 1 0.225 0.617 4 4 |
539194.0000000000 |
Sample Input 2 | Sample Output 2 |
---|---|
2 8 684841 506003 0.277 0.692 1 1 0.007 0.864 2 1 0.783 0.067 2 1 0.962 0.026 3 1 0.580 0.171 4 4 0.997 0.003 1 6 0.548 0.207 8 7 0.537 0.238 5 7 |
684556.2033270609 |
Sample Input 3 | Sample Output 3 |
---|---|
3 3 11 12 10 0.500 0.500 1 2 0.800 0.100 1 4 0.600 0.400 4 3 |
11.0555555556 |