#P3706. [SDOI2017] 硬币游戏
[SDOI2017] 硬币游戏
Description
On the weekend, the students were very bored. Someone suggested: let’s toss coins; whoever gets more heads wins.
Everyone thought this game suited the students’ style, but simply tossing coins was too monotonous.
To make it more interesting, they decided that one student would toss the coin many times, while the others would record the sequence of heads and tails.
Use to denote heads and to denote tails. After many tosses, we obtain a coin sequence. For example, means heads on the first toss and tails on the next two.
When should we stop tossing? They proposed that students each guess a sequence of length . When some student’s guessed sequence appears in the coin sequence, they stop tossing and that student wins. To ensure a unique winner, the sequences are pairwise distinct.
The students quickly made their guesses, and the exciting coin-tossing began. You want to know, assuming the coin is fair (heads and tails are equally likely), what is the probability that each student wins.
Input Format
The first line contains two integers .
The next lines each contain a string of length , representing the sequence guessed by the -th student.
Output Format
Output lines. The -th line contains the probability that the -th student wins. Your answer is accepted if the absolute error does not exceed .
3 3
THT
TTH
HTT
0.3333333333
0.2500000000
0.4166666667
Hint
For of the testdata, .
For of the testdata, .
Additionally, for of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号