atcoder#ABC189F. [ABC189F] Sugoroku2
[ABC189F] Sugoroku2
Score : points
Problem Statement
Takahashi is playing sugoroku.
The board has squares numbered to . Takahashi starts at Square and head to Square .
In this sugoroku, we use a wheel showing numbers from through with equal probability. In each turn, Takahashi spins the wheel and advances by the number shown by the wheel. When it makes him reach Square or go past it, he wins.
Some of the squares send him to Square when he stops on them. There are such squares: Square .
Find the expected value of the number of times Takahashi spins the wheel before he wins.
If it is impossible to win, print -1
instead.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the expected value of the number of times Takahashi spins the wheel before he wins.
Your output is considered as correct when its absolute or relative error from our answer is at most .
If it is impossible to win, print -1
instead.
2 2 0
1.5000
If the wheel shows in the first spin, he will need two spins to win; if the wheel shows in the first spin, he will need one spin to win. Thus, the expected number of spins is .
2 2 1
1
2.0000
If the wheel shows , he advances to Square , but it sends him back to Square . Thus, he keeps spinning the wheel until he gets and wins. The probability that he gets for the first time in the -th spin is , so the expected number of spins is .
100 6 10
11 12 13 14 15 16 17 18 19 20
-1
100000 2 2
2997 92458
201932.2222