#P6125. [JSOI2009] 有趣的游戏

    ID: 6894 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串动态规划 DP2009高斯消元AC 自动机

[JSOI2009] 有趣的游戏

Problem Description

Xiao Yangyang invented an interesting game: there are nn players, and each player has a letter sequence of length ll. Any two players' letter sequences are different. There are mm different letters in total, and all sequences are made up of these mm letters. For convenience, we use the first mm uppercase letters.

For example, when m=3,l=4m=3,l=4, ABAA\texttt{ABAA} and CBCA\texttt{CBCA} are two valid sequences.

Now Xiao Yangyang controls a magical machine. At each moment, the machine randomly generates one letter, and the probability that the ii-th letter is generated is piqi\dfrac{p_i}{q_i}. Obviously, k=1mpiqi=1\sum \limits_{k=1}^m \dfrac{p_i}{q_i}=1.

After TT moments, the machine will generate a letter sequence of length TT.

If at some moment a player finds that their letter sequence appears in the sequence generated by the machine, where “appears” means the player's sequence is a continuous substring of the machine's sequence, then we say this player wins and the game ends.

Now Xiao Yangyang is interested in this question: what is the probability that each player wins this game?

Input Format

The first line contains three positive integers n,l,mn,l,m, meaning there are nn people, each letter sequence has length ll, and there are mm letters in total.

The next mm lines each contain two non-negative integers p,qp, q, meaning the probability of randomly getting the ii-th letter is pq\frac{p}{q}.

The next nn lines each contain a letter sequence of length ll, representing the ii-th person's letter sequence.

Output Format

Output nn lines. Each line contains one real number, representing the probability that the ii-th person wins. Round the output to two decimal places.

3 2 2
1 2
1 2
AB
BA
AA
0.25
0.50
0.25
3 4 2
1 2
1 2
AABA
ABAA
BAAA
0.31
0.33
0.37

Hint

Constraints: 1n,l,m101 \leq n,l,m \leq 10, 0piqi100 \leq p_i \leq q_i \leq 10 and gcd(p,q)=1\gcd(p,q) = 1

Translated by ChatGPT 5