#P5750. [NOI1999] 钉子和小球
[NOI1999] 钉子和小球
Description
There is a triangular wooden board standing vertically. On it, nails are hammered in, and there are slots (see Figure 1 when ). The distance between each nail and its surrounding nails is . The width of each slot is also . Except for the leftmost and rightmost slots, each slot is aligned with a gap between two nails in the bottom row.
Let a small ball with diameter slightly smaller than roll down freely on the board, with its center initially aligned with the top nail. Each time the ball hits a nail, it may fall to the left or to the right (each with probability ), and the ball’s center will then align with the next nail it is going to hit. For example, Figure 2 shows one possible path of the ball.
We know that the probability that the ball lands in slot is $p_i = \frac{C_n^i}{2^n} = \frac{ n! }{ 2^n i! (n-i)! }$, where is the slot index, from left to right: .
Now the problem is to compute, after removing some nails, the probability that the ball lands in the slot with index . Assume that the nails in the bottom row will not be removed. For example, Figure 3 shows one possible path after some nails have been removed.

Figure 1 Figure 2 Figure 3.
Input Format
The first line contains integers () and (). The following lines give the nail information for the rows of nails on the board from top to bottom. In each line, * means the nail is still present, and . means the nail has been removed. Note that in these lines, spaces may appear anywhere.
Output Format
Output only one line: an irreducible fraction ( should be written as ), which is the probability that the ball lands in the slot with index .
Definition of an irreducible fraction: is an irreducible fraction if and only if and are positive integers and and have no common factor greater than .
5 2
*
* .
* * *
* . * *
* * * * *
7/16
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号