#P6125. [JSOI2009] 有趣的游戏
[JSOI2009] 有趣的游戏
Problem Description
Xiao Yangyang invented an interesting game: there are players, and each player has a letter sequence of length . Any two players' letter sequences are different. There are different letters in total, and all sequences are made up of these letters. For convenience, we use the first uppercase letters.
For example, when , and 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 -th letter is generated is . Obviously, .
After moments, the machine will generate a letter sequence of length .
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 , meaning there are people, each letter sequence has length , and there are letters in total.
The next lines each contain two non-negative integers , meaning the probability of randomly getting the -th letter is .
The next lines each contain a letter sequence of length , representing the -th person's letter sequence.
Output Format
Output lines. Each line contains one real number, representing the probability that the -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: , and 。
Translated by ChatGPT 5