Loading docs/string/prefix-function.md +5 −5 Original line number Diff line number Diff line Loading @@ -213,7 +213,7 @@ void compute_automaton(string s, vector<vector<int>>& aut) { } ``` 然而在这种形式下,对于小写字母表,算法的时间复杂度为 $O(n^2 26)$ 。注意到我们可以应用动态规划来利用表中已计算过的部分。只要我们从值 $j$ 变化到 $\pi[j - 1]$ ,那么我们实际上在说转移 $(j, c)$ 所到达的状态同转移 $(\pi[j - 1], c)$ 一样,但该答案我们之前已经精确计算过了。 然而在这种形式下,对于小写字母表,算法的时间复杂度为 $O(|\Sigma|n^2)$ 。注意到我们可以应用动态规划来利用表中已计算过的部分。只要我们从值 $j$ 变化到 $\pi[j - 1]$ ,那么我们实际上在说转移 $(j, c)$ 所到达的状态同转移 $(\pi[j - 1], c)$ 一样,但该答案我们之前已经精确计算过了。 ```cpp void compute_automaton(string s, vector<vector<int>>& aut) { Loading @@ -232,7 +232,7 @@ void compute_automaton(string s, vector<vector<int>>& aut) { } ``` 最终我们可在 $O(n 26)$ 的时间复杂度内构造该自动机。 最终我们可在 $O(|\Sigma|n)$ 的时间复杂度内构造该自动机。 该自动机在什么时候有用呢?首先,记得大部分时候我们为了一个目的使用字符串 $s + \# + t$ 的前缀函数:寻找字符串 $s$ 在字符串 $t$ 中的所有出现。 Loading Loading @@ -289,9 +289,9 @@ $$ ## 练习题目 - [UVA # 455 "Periodic Strings"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=396) - [UVA # 11022 "String Factoring"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1963) - [UVA # 11452 "Dancing the Cheeky-Cheeky"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2447) - [UVA 455 "Periodic Strings"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=396) - [UVA 11022 "String Factoring"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1963) - [UVA 11452 "Dancing the Cheeky-Cheeky"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2447) - [UVA 12604 - Caesar Cipher](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4282) - [UVA 12467 - Secret Word](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3911) - [UVA 11019 - Matrix Matcher](https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1960) Loading Loading
docs/string/prefix-function.md +5 −5 Original line number Diff line number Diff line Loading @@ -213,7 +213,7 @@ void compute_automaton(string s, vector<vector<int>>& aut) { } ``` 然而在这种形式下,对于小写字母表,算法的时间复杂度为 $O(n^2 26)$ 。注意到我们可以应用动态规划来利用表中已计算过的部分。只要我们从值 $j$ 变化到 $\pi[j - 1]$ ,那么我们实际上在说转移 $(j, c)$ 所到达的状态同转移 $(\pi[j - 1], c)$ 一样,但该答案我们之前已经精确计算过了。 然而在这种形式下,对于小写字母表,算法的时间复杂度为 $O(|\Sigma|n^2)$ 。注意到我们可以应用动态规划来利用表中已计算过的部分。只要我们从值 $j$ 变化到 $\pi[j - 1]$ ,那么我们实际上在说转移 $(j, c)$ 所到达的状态同转移 $(\pi[j - 1], c)$ 一样,但该答案我们之前已经精确计算过了。 ```cpp void compute_automaton(string s, vector<vector<int>>& aut) { Loading @@ -232,7 +232,7 @@ void compute_automaton(string s, vector<vector<int>>& aut) { } ``` 最终我们可在 $O(n 26)$ 的时间复杂度内构造该自动机。 最终我们可在 $O(|\Sigma|n)$ 的时间复杂度内构造该自动机。 该自动机在什么时候有用呢?首先,记得大部分时候我们为了一个目的使用字符串 $s + \# + t$ 的前缀函数:寻找字符串 $s$ 在字符串 $t$ 中的所有出现。 Loading Loading @@ -289,9 +289,9 @@ $$ ## 练习题目 - [UVA # 455 "Periodic Strings"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=396) - [UVA # 11022 "String Factoring"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1963) - [UVA # 11452 "Dancing the Cheeky-Cheeky"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2447) - [UVA 455 "Periodic Strings"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=396) - [UVA 11022 "String Factoring"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1963) - [UVA 11452 "Dancing the Cheeky-Cheeky"](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2447) - [UVA 12604 - Caesar Cipher](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4282) - [UVA 12467 - Secret Word](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3911) - [UVA 11019 - Matrix Matcher](https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1960) Loading