diff --git a/省选准备/assets/day2/AC-buildFail.cpp b/省选准备/assets/day2/AC-buildFail.cpp new file mode 100644 index 0000000..446b8dd --- /dev/null +++ b/省选准备/assets/day2/AC-buildFail.cpp @@ -0,0 +1,20 @@ +void buildFail() +{ + int h = 0, t = 0; + root->fail = &virt; + que[t++] = root; + while (h < t) + { + node *cur = que[h++]; + for (int i = 0; i < 26; i++) + { + node *f = cur->fail; + while (f->trans[i] == 0) f = f->fail; + f = f->trans[i]; + if (cur->trans[i]) + (que[t++] = cur->trans[i])->fail = f; + else + cur->trans[i] = f; + } + } +} \ No newline at end of file diff --git a/省选准备/省选基础算法.pdf b/省选准备/省选基础算法.pdf index b5129ac..2c7c50c 100644 Binary files a/省选准备/省选基础算法.pdf and b/省选准备/省选基础算法.pdf differ diff --git a/省选准备/省选基础算法.tex b/省选准备/省选基础算法.tex index e3d6a04..9675f90 100644 --- a/省选准备/省选基础算法.tex +++ b/省选准备/省选基础算法.tex @@ -158,4 +158,15 @@ Additionally, there are several pairs of people conducting adulterous relationsh \subparagraph{\href{http://poj.org/problem?id=2945}{POJ2945} - Find the Clones} $n$个基因片段,每个长度为$m$,输出$n$行表示重复出现$i$次$(1 \leq i \leq n)$的基因片段的个数 \codeinput[Find the Clones]{assets/day2/poj2945.cpp} +待续 +\subsection{Aho–Corasick Automaton} +\paragraph{简介} + 多模式串字符串匹配,Trie上的KMP,其中$next$数组变成了$fail$指针,功能相同。 +\paragraph{实现} + Trie的实现上文已经出现,所以此处不再重复。 +\codeinput[buildFail]{assets/day2/AC-buildFail.cpp} +\paragraph{练习题} +\subparagraph{\href{http://acm.hdu.edu.cn/showproblem.php?pid=2222}{HDU2222} - Keywords Search} +AC 自动机模板题,注意统计答案时,每个节点只能统计一次不要重复统计。 +\codeinput[Keywords Search]{assets/day2/poj3630.cpp} \end{document} \ No newline at end of file