AC自动机
文章平均质量分 92
qq_25243147
这个作者很懒,什么都没留下…
展开
-
ZOJ-3430 Detect the Virus(解码后最好用整数存)
题意:给出n个模式串,先将其解码;再给出m个主串,判断每个主串中出现了几个模式串(判断每个模式串是否出现过)。 WA1:没注意到解码后字符范围0~255; WAWAWAWA…:参考别人的解码后存字符,WA了很多次,后将解码存为int就过了 丑の代码: #include <cstdio> #include <queue> #include <cstring> using namespace std; const int N = 5e4 + 5; int trie[N][26原创 2020-08-18 09:20:39 · 77 阅读 · 0 评论 -
HDU-3065 病毒侵袭持续中(注意多组输入)
AC自动机模板题,判断各个串分别出现多少次 #include <cstdio> #include <queue> #include <cstring> using namespace std; const int N = 5e4 + 5; const int M = 2e6 + 5; const int C = 1e4 + 5; int trie[N][128]; //字典树 int cntword[N]; //记录该单词出现次数 int fail[N]; //原创 2020-08-06 21:56:11 · 82 阅读 · 0 评论 -
HDU-2896 病毒侵袭(AC自动机,ascii码匹配)
1、注意是ascii码,不单纯只是字母,所以范围0~127 2、scanf也能过,数据好像没有空格 3、输出total后有换行 #include <cstdio> #include <queue> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int N = 1e5 + 5; const int M = 1e4 + 5; in原创 2020-08-06 17:30:26 · 105 阅读 · 0 评论 -
HDU-2222 Keywords Search(AC自动机,不懂strlen放在函数中为什么会超时)
AC自动机模板,不过超时了很多次,参考了别人的代码后,起初把strlen放在insert()和query()中,后面strlen放在参数中就过了。 #include <cstdio> #include <queue> #include <cstring> using namespace std; const int N = 5e5 + 100; const int M = 1e6 + 5; int trie[N][26]; //字典树 int cntword[N]; /原创 2020-08-06 15:56:10 · 106 阅读 · 0 评论 -
菜鸟的AC自动机理解
参考这个博主https://blog.csdn.net/bestsort/article/details/82947639学习了这个算法 fail:用于找到当前成功匹配到的模式串的后缀的其他和这个后缀相等的模式串的最后一个字符; 在查询时把j=fail[j]可以把与当前模式串的后缀相同的 其他模式串扫一遍。 ...原创 2020-08-06 01:29:08 · 73 阅读 · 0 评论