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\ldots\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.