#P3706. [SDOI2017] 硬币游戏

    ID: 1338 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>字符串2017各省省选山东Special Judge枚举,暴力构造

[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 H\texttt H to denote heads and T\texttt T to denote tails. After many tosses, we obtain a coin sequence. For example, HTT\texttt{HTT} means heads on the first toss and tails on the next two.

When should we stop tossing? They proposed that nn students each guess a sequence of length mm. When some student’s guessed sequence appears in the coin sequence, they stop tossing and that student wins. To ensure a unique winner, the nn sequences are pairwise distinct.

The nn 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 n,mn, m.

The next nn lines each contain a string of length mm, representing the sequence guessed by the ii-th student.

Output Format

Output nn lines. The ii-th line contains the probability that the ii-th student wins. Your answer is accepted if the absolute error does not exceed 10610^{-6}.

3 3
THT
TTH
HTT
0.3333333333
0.2500000000
0.4166666667

Hint

For 10%10\% of the testdata, 1n,m31 \le n, m \le 3.

For 40%40\% of the testdata, 1n,m181 \le n, m \le 18.

Additionally, for 20%20\% of the testdata, n=2n = 2.

For 100%100\% of the testdata, 1n,m3001 \le n, m \le 300.

Translated by ChatGPT 5