QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#9740. Aho-Corasick 自动机

الإحصائيات

Little A 有许多字符串,每个字符串的字符集均为 $\{1, 2, \dots, m\}$。他为这些字符串构建了一个 Trie,并基于该 Trie 构建了一个 AC 自动机。

然而,由于 Little A 的疏忽,原始字符串和构建好的 AC 自动机都丢失了。Little A 只记得所有原始字符串的长度都不超过 $d$,且构建出的 AC 自动机有 $n$ 个顶点,字符集为 $\{1, 2, \dots, m\}$。

现在,Little A 想知道有多少种不同的 AC 自动机可能是他当初构建的那一个。由于答案可能很大,你只需要输出结果对 $998244353$ 取模后的值。

AC 自动机的定义如下:

  1. Trie $T$ 是一棵无标号的有根树,其中每条边都标有一个字符。Trie 中的顶点 $x$ 不能有两个子顶点 $y$ 和 $z$,使得边 $(x, y)$ 和 $(x, z)$ 标有相同的字符。
  2. 给定一个根为 $r$ 的 Trie $T$,对于顶点 $x$,由 $x$ 表示的字符串是从 $r$ 到 $x$ 的路径上所有边上的字符连接而成的。特别地,根 $r$ 表示的字符串为空串。可以证明,没有两个不同的顶点表示相同的字符串。
  3. 我们称字符串 $S$ 存在于 Trie $T$ 中,当且仅当存在一个顶点 $x$,使得 $x$ 表示的字符串为 $S$。
  4. 为某些字符串 $S_1, S_2, \dots, S_k$ 构建 Trie $T$ 意味着找到一个顶点数最少的 Trie $T$,使得所有字符串 $S_i$ 都存在于 $T$ 中。可以证明,这样的 Trie 在无标号时是唯一的。
  5. Trie $T$ 的 fail 树 $F$ 是一棵根为 $r$ 的树。定义 $S_x$ 为顶点 $x$ 表示的字符串。对于非根顶点 $x$,令 $U$ 为 $S_x$ 的最长真后缀(真后缀指不等于 $S_x$ 的后缀),且 $U$ 存在于 $T$ 中。那么,$fail_x$ 定义为满足 $S_{fail_x} = U$ 的顶点。注意 $S_x$ 的空后缀总是存在于 $T$ 中,因此 $fail_x$ 总是存在的。$F$ 的边集为 $\{(x, fail_x) \mid x \in [1, n], x \neq r\}$。可以证明这些边构成一棵树。
  6. 合并 Trie $T$ 和它的 fail 树 $F$ 意味着顶点集保持不变($T$ 和 $F$ 的顶点集相同),并将边和边上的字符合并,从而得到图,即 $T$ 的 AC 自动机 $A$。此时,$A$ 同时包含标有字符的边和无标号的边。

当且仅当两个 AC 自动机具有相同数量的顶点,且存在两个顶点标号方案(假设它们是长度等于顶点数的两个排列),使得以下条件成立时,它们被认为是相同的:

  1. 两个 AC 自动机的根相同。
  2. 对于任意一对顶点 $x, y$,在两个 AC 自动机中,要么它们之间都没有边,要么都有边且边上的字符相同,或者两条边都没有标号。

输入格式

一行,包含三个整数 $n, m, d$ ($1 \le n, m, d \le 100$),分别表示 AC 自动机的顶点数、字符集大小以及所有字符串长度的上限。

输出格式

一行,包含一个整数,表示答案。

样例

输入 1

3 2 2

输出 1

5

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.