AC自动机
tomjobs
别慌,慌也没用
展开
-
P5357 【模板】AC自动机(二次加强版)(AC自动机拓扑排序优化)
思路: 最坏情况下FailFailFail树上每跳一次深度减1,那么queryqueryquery操作的最坏复杂度为O(∣∑T∣∗∣S∣)O(|∑T|*|S|)O(∣∑T∣∗∣S∣),本题中的话就是2e5∗2e62e5*2e62e5∗2e6,这是不可接受的。 不过因为很明显仅考虑failfailfail指针的话,每个节点只会指向深度更小的节点,所以不会成环,就构成了一个DAG图。每个节点的答案由为自己的节点的答案的和。 因此,queryqueryquery的过程我们不暴力跳failfailfail指针,只.原创 2021-02-04 11:30:06 · 409 阅读 · 0 评论 -
P5357 【模板】AC自动机(二次加强版)
思路: 复习了一下AC自动机。字典树上节点iii的Fail指针指向的jjj,代表s[j]s[j]s[j]结尾前缀为s[i]s[i]s[i]结尾前缀的后缀,且为能匹配的最长后缀。 本题中按照AC自动机的基础操作求出每个模板串在文本中的出现次数然后取最大值输出即可。 #include <vector> #include <cstdio> #include <cstring> #include <queue> #include <algorithm> .原创 2021-02-04 00:33:28 · 299 阅读 · 0 评论 -
PreSuffix ZOJ - 3995(AC自动机 fail树上跑LCA)
We define a string of length ll as an array S[1…l]S[1…l]. All the elements within it belongs to a finite set \sum={a,b,…,z}∑={a,b,…,z}. Let \text{Prefix}(S,i)=S[1…i]Prefix(S,i)=S[1…i] be one prefix of SS with a length of ii. Similarly, \text{Suffix}(S,j)=S原创 2020-10-13 23:30:05 · 209 阅读 · 0 评论 -
ICPC Central Europe Regional Contest 2019 K. K==S(AC自动机+矩阵快速幂)
Progressive hard octave rock tunes (so-called “phorts”) are written using a specifific music notation. This flflavor of rock is built on just 13 difffferent note pitches, other pitches (in other octaves)are considered to be an outdated musical ballast. Eac原创 2020-06-21 20:08:59 · 552 阅读 · 0 评论 -
DNA Sequence POJ - 2778(AC自动机+矩阵快速幂)
It’s well known that DNA Sequence is a sequence only contains A, C, T and G, and it’s very useful to analyze a segment of DNA Sequence,For example, if a animal’s DNA sequence contains segment ATC then it may mean that the animal may have a genetic disease.原创 2020-06-21 18:40:16 · 658 阅读 · 5 评论 -
HDU2222 Keywords Search(AC自动机模板题)
Problem Description In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiskey also wants to bring this feature to his image retrieval system. Every image have a long description, when users type some keywords to find原创 2020-06-21 14:52:10 · 244 阅读 · 0 评论