QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 2048 MB Puntuación total: 100

#16198. 数字生成器

Estadísticas

在 Binary 赌场中,最受欢迎的游戏之一是“二进制生成器”(The Binary Generator)。该游戏由多名玩家使用一枚硬币进行。每位玩家首先选择一个给定长度的、由正面(heads)和反面(tails)组成的序列。此后,玩家或赌场开始抛掷硬币,最先让自己的序列作为抛掷结果的连续子序列出现的玩家获得胜利。

你曾认为玩家选择的所有序列都是等价的,因此选择什么序列并不重要。然而,在输光了所有的钱之后,你对此产生了一些怀疑。请编写一个程序来证明你是错的。给定一组长度相同的正面和反面序列,求出在其中任意一个玩家选择的序列作为抛掷序列的连续子序列出现之前,需要进行的硬币抛掷次数的期望值。 硬币抛掷次数的期望值是指,在所有导致某位玩家获胜的可能抛掷序列中,抛掷序列长度的加权平均值(以其概率为权重)。

输入格式

输入的第一行包含两个整数 $W$ 和 $B$($1 \le W \le 10$,$1 \le B \le 30$),分别表示玩家序列的数量和玩家序列的长度。

接下来的 $W$ 行,每行包含一个由 $B$ 个字母组成的序列。每个字母为表示正面的 'H' 或表示反面的 'T'。

输出格式

输出一个实数,表示期望的抛掷次数。如果输出与正确答案的差值不超过 $0.1$,则认为输出是正确的。

样例

输入样例 1

1 1
H

输出样例 1

2.0

输入样例 2

2 3
HHT
THT

输出样例 2

5.0

输入样例 3

2 3
HHH
HHT

输出样例 3

7.0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.