QOJ.ac

QOJ

Süre Sınırı: 10 s Bellek Sınırı: 2048 MB Toplam puan: 100

#8684. 骰子已擲出

İstatistikler

你玩緊一個用多粒公平六面骰嘅遊戲。每粒骰每一面都有一個符號。遊戲目標係擲骰,再用每粒骰頂面嘅符號砌成一個有效單字。如果砌唔到,可以重新擲骰再試。

problem_8684_e748ebe84691995c030c49e69ce185d3.png

圖 K.1:五粒骰砌成對應輸入例子 1 嘅有效單字。

假設有五粒骰:其中一粒有字母 A、B、C、D、E 同 P(簡寫做 ABCDEP),其餘分別有 AEHOXU、AISOLR、ABCDEF 同 ABCSCC。第一次擲出之後,各粒骰頂面依次係 P、X、R、E 同 S。因為呢啲字母排唔成有效單字,你決定留低 P、S 同 E,重擲其餘骰,嘗試砌出 PARSE、PAUSE、PHASE、POISE、PROSE、PULSE 或 PURSE 等單字。嗰兩粒骰擲到 E 同 A,於是五個字母變成 P、E、A、E 同 S。你仍然諗唔到有效單字,所以決定留低四個字母,只重擲最後嗰粒骰;佢有三面都係字母 C。咁做就有 50% 機會砌成最後嘅有效單字 PEACE,如圖 K.1。

擲一粒骰時,每一面向上嘅機會一樣。假設你用最優策略,要砌成有效單字,擲骰次數嘅期望值係幾多?

輸入格式

輸入第一行有兩個數 $d$ 同 $w$,$d$($1 \le d \le 6$)係骰子數目,$w$($1 \le w \le 2 \cdot 10^5$)係字典入面有效單字嘅數目。之後 $d$ 行,每行有 6 個符號,各自對應嗰粒骰嘅一面。最後 $w$ 行有字典入面 $w$ 個唔同嘅有效單字。每個單字啱啱有 $d$ 個符號。

輸入所有符號都係大楷字母(A–Z)或者數字(0–9)。

輸出格式

如果可以砌成有效單字,輸出用最優策略時砌成有效單字所需擲骰次數嘅期望值。否則輸出 impossible。答案嘅絕對誤差或者相對誤差最多係 $10^{-6}$。

例子

輸入格式 1

5 8
ABCDEP
AEHOXU
AISOLR
ABCDEF
ABCSCC
PARSE
PAUSE
PHASE
POISE
PROSE
PULSE
PURSE
PEACE

輸出格式 1

9.677887141

輸入格式 2

2 1
AAAAAA
BBBBBB
AB

輸出格式 2

1.0

輸入格式 3

3 1
123456
123456
123456
666

輸出格式 3

10.555444555

輸入格式 4

2 1
ABCDEF
GHI234
AB

輸出格式 4

impossible

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.