Loading docs/misc/gray-code.md +1 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,7 @@ int rev_g(int g) { ## 习题 - [CSP S2 2019 D1T1](https://www.luogu.org/problem/P5657) Difficulty: easy - [SGU #249 Matrix](http://codeforces.com/problemsets/acmsguru/problem/99999/249) Difficulty: medium - 2019 CSP-S D1T1 Loading docs/string/pam.md +67 −65 Original line number Diff line number Diff line ## 概述 回文树 (EER Tree,Palindromic Tree,也被称为回文自动机) 是一种可以存储一个串中所有回文子串的高效数据结构,最初是由 Mikhail Rubinchik 和 Arseny M. Shur 在 2015 年发表。它的灵感来源于后缀树等字符串后缀数据结构,使用回文树可以简单高效地解决一系列涉及回文串的问题。 回文树 (EER Tree,Palindromic Tree,也被称为回文自动机)是一种可以存储一个串中所有回文子串的高效数据结构,最初是由 Mikhail Rubinchik 和 Arseny M. Shur 在 2015 年发表。它的灵感来源于后缀树等字符串后缀数据结构,使用回文树可以简单高效地解决一系列涉及回文串的问题。 ## 结构 Loading @@ -8,7 +8,7 @@  和其它自动机类似的,回文树也是由转移边和后缀链接 (fail 指针) 组成,每个节点都可以代表一个回文子串。 和其它自动机类似的,回文树也是由转移边和后缀链接 (fail 指针)组成,每个节点都可以代表一个回文子串。 因为回文串长度分为奇数和偶数,我们可以像 manacher 那样加入一个不在字符集中的字符(如 '#')作为分隔符来将所有回文串的长度都变为奇数,但是这样过于麻烦了。有没有更好的办法呢? Loading Loading @@ -48,9 +48,9 @@ 证明:考虑使用数学归纳法。 + 当 $|s| =1$ 时,$s$ 只有一个字符,同时也只有一个子串,并且这个子串是回文的,因此结论成立。 - 当 $|s| =1$ 时, $s$ 只有一个字符,同时也只有一个子串,并且这个子串是回文的,因此结论成立。 + 当 $|s| >1$ 时,设 $t=sc$,其中 $t$ 表示 $s$ 最后增加一个字符 $c$ 后形成的字符串,假设结论对 $s$ 串成立。考虑以最后一个字符 $c$ 结尾的回文子串,假设它们的左端点由小到大排序为 $l_1,l_2,\dots,l_k$。由于 $t[l_1..|t|]$ 是回文串,因此对于所有位置 $l_1 \le p \le |t|$,有 $t[p..|t|]=t[l_1..l_1+|t|-p]$。所以,对于 $1 < i \le k$,$t[l_i..|t|]$ 已经在 $t[1..|t|-1]$ 中出现过。因此,每次增加一个字符,本质不同的回文子串个数最多增加 $1$ 个。 - 当 $|s| >1$ 时,设 $t=sc$ ,其中 $t$ 表示 $s$ 最后增加一个字符 $c$ 后形成的字符串,假设结论对 $s$ 串成立。考虑以最后一个字符 $c$ 结尾的回文子串,假设它们的左端点由小到大排序为 $l_1,l_2,\dots,l_k$ 。由于 $t[l_1..|t|]$ 是回文串,因此对于所有位置 $l_1 \le p \le |t|$ ,有 $t[p..|t|]=t[l_1..l_1+|t|-p]$ 。所以,对于 $1 < i \le k$ , $t[l_i..|t|]$ 已经在 $t[1..|t|-1]$ 中出现过。因此,每次增加一个字符,本质不同的回文子串个数最多增加 $1$ 个。 由数学归纳法,可知该定理成立。 Loading Loading @@ -100,9 +100,11 @@ namespace pam { return sz; } void clear() { sz = -1; last = 0; sz = -1; last = 0; s[tot = 0] = '$'; node(0); node(-1); node(0); node(-1); fail[0] = 1; } int getfail(int x) { Loading Loading @@ -130,7 +132,7 @@ namespace pam { } return ans; } } } // namespace pam char s[maxn]; Loading @@ -147,20 +149,20 @@ int main() { ## 例题 + [最长双回文串](https://www.luogu.org/problem/P4555) - [最长双回文串](https://www.luogu.org/problem/P4555) + [拉拉队排练](https://www.luogu.org/problem/P1659) - [拉拉队排练](https://www.luogu.org/problem/P1659) + [「SHOI2011」双倍回文](https://www.luogu.org/problem/P4287) - [「SHOI2011」双倍回文](https://www.luogu.org/problem/P4287) + [HDU 5421 Victor and String](http://acm.hdu.edu.cn/showproblem.php?pid=5421) - [HDU 5421 Victor and String](http://acm.hdu.edu.cn/showproblem.php?pid=5421) + [CodeChef Palindromeness](https://www.codechef.com/LTIME23/problems/PALPROB) - [CodeChef Palindromeness](https://www.codechef.com/LTIME23/problems/PALPROB) ## 相关资料 + [EERTREE: An Efficient Data Structure for Processing Palindromes in Strings](https://arxiv.org/pdf/1506.04862) - [EERTREE: An Efficient Data Structure for Processing Palindromes in Strings](https://arxiv.org/pdf/1506.04862) + [Palindromic tree](http://adilet.org/blog/palindromic-tree/) - [Palindromic tree](http://adilet.org/blog/palindromic-tree/) + 2017 年 IOI 国家候选队论文集 回文树及其应用 翁文涛 - 2017 年 IOI 国家候选队论文集 回文树及其应用 翁文涛 Loading
docs/misc/gray-code.md +1 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,7 @@ int rev_g(int g) { ## 习题 - [CSP S2 2019 D1T1](https://www.luogu.org/problem/P5657) Difficulty: easy - [SGU #249 Matrix](http://codeforces.com/problemsets/acmsguru/problem/99999/249) Difficulty: medium - 2019 CSP-S D1T1 Loading
docs/string/pam.md +67 −65 Original line number Diff line number Diff line ## 概述 回文树 (EER Tree,Palindromic Tree,也被称为回文自动机) 是一种可以存储一个串中所有回文子串的高效数据结构,最初是由 Mikhail Rubinchik 和 Arseny M. Shur 在 2015 年发表。它的灵感来源于后缀树等字符串后缀数据结构,使用回文树可以简单高效地解决一系列涉及回文串的问题。 回文树 (EER Tree,Palindromic Tree,也被称为回文自动机)是一种可以存储一个串中所有回文子串的高效数据结构,最初是由 Mikhail Rubinchik 和 Arseny M. Shur 在 2015 年发表。它的灵感来源于后缀树等字符串后缀数据结构,使用回文树可以简单高效地解决一系列涉及回文串的问题。 ## 结构 Loading @@ -8,7 +8,7 @@  和其它自动机类似的,回文树也是由转移边和后缀链接 (fail 指针) 组成,每个节点都可以代表一个回文子串。 和其它自动机类似的,回文树也是由转移边和后缀链接 (fail 指针)组成,每个节点都可以代表一个回文子串。 因为回文串长度分为奇数和偶数,我们可以像 manacher 那样加入一个不在字符集中的字符(如 '#')作为分隔符来将所有回文串的长度都变为奇数,但是这样过于麻烦了。有没有更好的办法呢? Loading Loading @@ -48,9 +48,9 @@ 证明:考虑使用数学归纳法。 + 当 $|s| =1$ 时,$s$ 只有一个字符,同时也只有一个子串,并且这个子串是回文的,因此结论成立。 - 当 $|s| =1$ 时, $s$ 只有一个字符,同时也只有一个子串,并且这个子串是回文的,因此结论成立。 + 当 $|s| >1$ 时,设 $t=sc$,其中 $t$ 表示 $s$ 最后增加一个字符 $c$ 后形成的字符串,假设结论对 $s$ 串成立。考虑以最后一个字符 $c$ 结尾的回文子串,假设它们的左端点由小到大排序为 $l_1,l_2,\dots,l_k$。由于 $t[l_1..|t|]$ 是回文串,因此对于所有位置 $l_1 \le p \le |t|$,有 $t[p..|t|]=t[l_1..l_1+|t|-p]$。所以,对于 $1 < i \le k$,$t[l_i..|t|]$ 已经在 $t[1..|t|-1]$ 中出现过。因此,每次增加一个字符,本质不同的回文子串个数最多增加 $1$ 个。 - 当 $|s| >1$ 时,设 $t=sc$ ,其中 $t$ 表示 $s$ 最后增加一个字符 $c$ 后形成的字符串,假设结论对 $s$ 串成立。考虑以最后一个字符 $c$ 结尾的回文子串,假设它们的左端点由小到大排序为 $l_1,l_2,\dots,l_k$ 。由于 $t[l_1..|t|]$ 是回文串,因此对于所有位置 $l_1 \le p \le |t|$ ,有 $t[p..|t|]=t[l_1..l_1+|t|-p]$ 。所以,对于 $1 < i \le k$ , $t[l_i..|t|]$ 已经在 $t[1..|t|-1]$ 中出现过。因此,每次增加一个字符,本质不同的回文子串个数最多增加 $1$ 个。 由数学归纳法,可知该定理成立。 Loading Loading @@ -100,9 +100,11 @@ namespace pam { return sz; } void clear() { sz = -1; last = 0; sz = -1; last = 0; s[tot = 0] = '$'; node(0); node(-1); node(0); node(-1); fail[0] = 1; } int getfail(int x) { Loading Loading @@ -130,7 +132,7 @@ namespace pam { } return ans; } } } // namespace pam char s[maxn]; Loading @@ -147,20 +149,20 @@ int main() { ## 例题 + [最长双回文串](https://www.luogu.org/problem/P4555) - [最长双回文串](https://www.luogu.org/problem/P4555) + [拉拉队排练](https://www.luogu.org/problem/P1659) - [拉拉队排练](https://www.luogu.org/problem/P1659) + [「SHOI2011」双倍回文](https://www.luogu.org/problem/P4287) - [「SHOI2011」双倍回文](https://www.luogu.org/problem/P4287) + [HDU 5421 Victor and String](http://acm.hdu.edu.cn/showproblem.php?pid=5421) - [HDU 5421 Victor and String](http://acm.hdu.edu.cn/showproblem.php?pid=5421) + [CodeChef Palindromeness](https://www.codechef.com/LTIME23/problems/PALPROB) - [CodeChef Palindromeness](https://www.codechef.com/LTIME23/problems/PALPROB) ## 相关资料 + [EERTREE: An Efficient Data Structure for Processing Palindromes in Strings](https://arxiv.org/pdf/1506.04862) - [EERTREE: An Efficient Data Structure for Processing Palindromes in Strings](https://arxiv.org/pdf/1506.04862) + [Palindromic tree](http://adilet.org/blog/palindromic-tree/) - [Palindromic tree](http://adilet.org/blog/palindromic-tree/) + 2017 年 IOI 国家候选队论文集 回文树及其应用 翁文涛 - 2017 年 IOI 国家候选队论文集 回文树及其应用 翁文涛