#P4569. [BJWC2011] 禁忌
[BJWC2011] 禁忌
Description
People in Magic Land always mention the legend: their ancestor John helped Koishi and her elder sister Satori on that eastern island, and they ultimately fought to a draw. After that, Koishi recovered her mind-reading ability...
Now, in an age when John has become a legend, people who revisit that island find that Koishi has run into new trouble.
This time she encounters Flandre Scarlet — she has the ability to use taboo magic without being harmed.
To explain what taboo magic is and how it causes damage, we introduce the following concepts:
- Every non-empty string over an alphabet corresponds to a spell. Here is the set containing the first lowercase letters.
- There is a set that contains strings over the alphabet . Each string in is called a taboo string (taboo string).
- A spell, or equivalently its corresponding string , causes damage to the user due to taboos as follows: partition into several segments, and consider the number of segments that are taboo strings. Different partitions may yield different counts; the maximum count is the damage.
Because she can read minds, Koishi always uses Flandre Scarlet’s spells at random. Concretely, her spells correspond exactly to all strings of length over the alphabet .
However, some of Flandre Scarlet’s spells are taboo. Due to her special nature, she can use taboo magic without taking damage, but Koishi cannot. Poor Koishi faces the threat of taboo damage every time she uses one of Flandre’s spells.
You need to compute the expected taboo damage when Koishi picks each of Flandre’s spells with equal probability, i.e., uniformly over all length- strings over .
Input Format
The first line contains three positive integers , , .
The next lines each contain a string , representing a taboo string.
Output Format
Output a non-negative real number, the expected taboo damage. Your answer must have an absolute error not exceeding .
2 4 2
aa
abb
0.75
Hint
[Explanation for Sample 1]
There are different spells.
Note that the taboo damage of "aabb" is 1 rather than 2.
Constraints
- In at least 40% of the testdata: .
- For 100% of the testdata: , , .
- The testdata guarantees that the length of each string does not exceed , and is non-empty.
- The testdata guarantees that each contains only the first lowercase letters.
- The testdata guarantees that the set has no duplicate elements; that is, for any distinct and , .
Translated by ChatGPT 5
京公网安备 11011102002149号