QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#3018. 無前綴編碼

Statistics

考慮 $n$ 個由小寫字母組成嘅原始字串,當中冇任何一個原始字串係另一個原始字串嘅前綴。而家考慮揀出其中 $k$ 個字串(每個字串最多揀一次),再將佢哋串接埋一齊。可以產生嘅合成字串數量係:

$$n \times (n-1) \times (n-2) \times \cdots \times (n-k+1)$$

將用呢個方法得到嘅所有合成字串按字母順序排序。畀你一個測試合成字串,保證佢喺呢個列表入面。求呢個測試合成字串喺排序後嘅所有合成字串列表中嘅位置,答案對 $10^9+7$ 取模。列表中第一個合成字串嘅位置係 $1$。

輸入格式

每份輸入只有一組測試資料。請留意,你嘅程式可能會用唔同輸入執行多次。每組測試資料嘅第一行有兩個整數,依次係 $n$ 同 $k$($1 \le k \le n$),其中 $n$ 係原始字串嘅數量,$k$ 係用嚟組成合成字串所揀嘅原始字串數量。$n$ 同 $k$ 嘅上限受以下幾段嘅字串限制約束。

之後 $n$ 行,每行有一個由一個或以上小寫字母 a..z 組成嘅字串。呢啲就係嗰 $n$ 個原始字串。保證冇任何一個原始字串係另一個原始字串嘅前綴。

最後一行有另一個只由小寫字母 a..z 組成嘅字串。呢個就係你要搵出佢喺排序列表中位置嘅測試合成字串。保證呢個字串係由 $k$ 個互不相同嘅原始字串串接而成。

所有輸入字串(包括測試字串)嘅長度總和唔會超過 $10^6$ 個字母。

輸出格式

輸出一個整數,表示測試合成字串喺排序後嘅合成字串列表中嘅位置。將呢個數對 $10^9+7$ 取模後輸出。

樣例

輸入格式 1

5 3
a
b
c
d
e
cad

輸出格式 1

26

輸入格式 2

8 8
font
lewin
darko
deon
vanb
johnb
chuckr
tgr
deonjohnbdarkotgrvanbchuckrfontlewin

輸出格式 2

12451

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.