atcoder#ABC189F. [ABC189F] Sugoroku2

[ABC189F] Sugoroku2

Score : 600600 points

Problem Statement

Takahashi is playing sugoroku.

The board has N+1N+1 squares numbered 00 to NN. Takahashi starts at Square 00 and head to Square NN.

In this sugoroku, we use a wheel showing numbers from 11 through MM 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 NN or go past it, he wins.

Some of the squares send him to Square 00 when he stops on them. There are KK such squares: Square A1,,AKA_1, \ldots, A_K.

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.
  • 1N1051 \leq N \leq 10^5
  • 1M1051 \leq M \leq 10^5
  • 0K100 \leq K \leq 10
  • 0<A1<<AK<N0 < A_1 < \ldots < A_K < N

Input

Input is given from Standard Input in the following format:

NN MM KK

A1A_1 \ldots AKA_K

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 10310^{-3}. If it is impossible to win, print -1 instead.

2 2 0
1.5000

If the wheel shows 11 in the first spin, he will need two spins to win; if the wheel shows 22 in the first spin, he will need one spin to win. Thus, the expected number of spins is 1.51.5.

2 2 1
1
2.0000

If the wheel shows 11, he advances to Square 11, but it sends him back to Square 00. Thus, he keeps spinning the wheel until he gets 22 and wins. The probability that he gets 22 for the first time in the ii-th spin is 12i\frac{1}{2^i}, so the expected number of spins is i=1(i×12i)=2\sum_{i = 1}^{\infty} (i \times \frac{1}{2^i}) = 2.

100 6 10
11 12 13 14 15 16 17 18 19 20
-1
100000 2 2
2997 92458
201932.2222