#P3330. Movie Theater Parking
Movie Theater Parking
Movie Theater Parking
During a rare break the class decides to go to the movies. However, due to the large number of people, it is very difficult to get the entire class watching the same show. Finally, they find a small theater in a narrow alley where the seating assignment is very special. The theater has \(K\) seats, numbered from 1 to K. When a person buys a ticket, they are randomly assigned an integer \(L\) with equal probability from 1 to K.
The assignment is done as follows: if seat \(L\) is free, the person sits there; otherwise, the person checks seat \(L+1\), and so on. If no seat numbered \(\ge L\) is available, then the person has to stand (i.e. receives a standing ticket).
There are \(N\) people in the class (including Xiao Bai), and as a math enthusiast Xiao Bai wonders: What is the probability that every person in the class gets a seat?
Note: A sequence of desired seat numbers \(L_1,L_2,\dots,L_N\) leads to everyone getting a seat if the following parking process succeeds. In fact, if one sorts the selected numbers in non‐decreasing order as \(a_1\le a_2\le\cdots\le a_N\), then the i-th person will eventually be assigned seat </em>\(s_i = \max(a_i, s_{i-1}+1)\)</em> (with \(s_0=0\)). The process is successful if \(s_N \le K\). It can be shown that the total number of successful assignments is exactly
[ \text{SuccessCount} = (K-N+1)\cdot (K+1)^{N-1}, \quad \text{for } N\le K, \quad\text{and 0 if } N>K. ]
Thus, the desired probability is given by
[ P = \frac{(K-N+1)\cdot (K+1)^{N-1}}{K^N} = \frac{K-N+1}{K} \left(\frac{K+1}{K}\right)^{N-1}. ]
inputFormat
The input consists of two space‐separated integers N and K on a single line. Here N (0 \(\le\) N) is the number of people in the class and K (K \(\ge\) N) is the number of seats in the theater. If N > K, output 0 as it is impossible for everyone to have a seat.
outputFormat
Output a floating–point number representing the probability that every person gets a seat. The answer should be printed with 6 decimal places.
sample
2 3
0.888889