#P4569. [BJWC2011] 禁忌

    ID: 3453 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串2011北京Special Judge概率论,统计矩阵乘法

[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:

  1. Every non-empty string over an alphabet AA corresponds to a spell. Here AA is the set containing the first alphabetalphabet lowercase letters.
  2. There is a set TT that contains NN strings over the alphabet AA. Each string in TT is called a taboo string (taboo string).
  3. A spell, or equivalently its corresponding string ss, causes damage to the user due to taboos as follows: partition ss 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 lenlen over the alphabet AA.

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-lenlen strings over AA.

Input Format

The first line contains three positive integers NN, lenlen, alphabetalphabet.
The next NN lines each contain a string TiT_i, 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 10610^{-6}.

2 4 2
aa
abb
0.75

Hint

[Explanation for Sample 1]
There are 24=162^4 = 16 different spells.

Note that the taboo damage of "aabb" is 1 rather than 2.

Constraints

  • In at least 40% of the testdata: N=1N = 1.
  • For 100% of the testdata: N5N \le 5, len109len \le 10^9, 1alphabet261 \le alphabet \le 26.
  • The testdata guarantees that the length of each string TiT_i does not exceed 1515, and is non-empty.
  • The testdata guarantees that each TiT_i contains only the first alphabetalphabet lowercase letters.
  • The testdata guarantees that the set TT has no duplicate elements; that is, for any distinct ii and jj, TiTjT_i \ne T_j.

Translated by ChatGPT 5