
AC自动机
文章平均质量分 83
DT2131
Rage, rage against the dying of the light.Do not go gentle into that good night.
展开
-
HDU 5880 Family View (AC自动机)
题意: 模拟敏感词和谐器,T 组数据,每组数据 N 个子串,一个母串,输出和谐的母串 思路: 母串带空格,用gets就行,用子串的长度做标记,匹配时若匹配到,和谐掉’标记数‘个数个字符就行。 代码: #include #include #include #include #include using namespace std; struct Trie { int ne原创 2016-11-16 10:58:52 · 531 阅读 · 0 评论 -
HDU 5384 Danganronpa AC自动机
题意: T 组数据, N 个母串 ,M 个子串,求每个母串的匹配 思路: 子串可能相同,算多次匹配 代码: #include #include #include #include #include using namespace std; struct Trie { int next[100010][26],fail[100010],end[100010]; i原创 2016-11-16 10:53:09 · 389 阅读 · 0 评论 -
HDU 2222 Keywords Search AC自动机模板题
题意: T组样例,N个子串,查询母串中子串出现的次数。 思路: ac自动机模板题 代码: (kuangbin模板) #include #include #include #include #include using namespace std; struct Trie { int next[500010][26],fail[500010],end[500010];原创 2016-11-16 11:00:21 · 319 阅读 · 0 评论 -
HDU-3065 病毒侵袭持续中 AC自动机
题意: 中文题 思路: 统计一下就行 代码: #include #include #include #include #include using namespace std; int res[1010]; struct Trie { int next[1010*55][128],fail[1010*55],end[1010*55]; int root,L;原创 2016-11-16 10:48:41 · 449 阅读 · 0 评论 -
HDU 2896 病毒侵袭 AC自动机
题意: 中文题 思路: 不同的子串打上各自的id,跑匹配的时候统计一下就行。注意一个子串可能会多次出现在母串中 代码: #include #include #include #include #include using namespace std; struct Trie { int next[150000][128],fail[150000],end[150000原创 2016-11-16 10:45:41 · 322 阅读 · 0 评论 -
POJ 3450 Corporate Identity( AC自动机 )
题意: 给出 N 个串,问这几个串的最长公共字串是什么?若有多个输出字典序最小的。 思路: 由于 N 小于 4000 且长度小于 200。我们完全可以用暴力的方法。 不妨将第一个串当成母串,枚举出他的所有子串。并将其所有子串作为模式串,与其他的串进行匹配。 这里匹配的方法直接利用了 AC自动机 。 由于要输原创 2017-02-19 03:13:11 · 489 阅读 · 0 评论 -
SPOJ694 Distinct Substrings (trie 树)
题意: 给出一个字符串,问有几个不同子串 思路: 我是在学习后缀数组时做到这道题的,但是我的第一反应并不是后缀数组的做法,而是 AC 自动机。 AC 自动机 的本质就是记录不同状态的子串。类似于在 数字逻辑 一课 中所学的状态转移表。 子串的状态数就是 AC 自动机 中的状态数。 为了得到母串中的每个子串,原创 2017-02-09 01:36:16 · 806 阅读 · 0 评论 -
HDU - 4787 GRE Words Revenge (在线AC自动机,自动机的重构)
转载自:http://blog.youkuaiyun.com/no__stop/article/details/16823479 题意:学习英语单词,有n个操作,每次可以读入一个单词,或者询问一个文本串,查询有多少个不同的单词已读入。文本是被加密过的,加密的方法就是将文本旋转上一次询问的答案次。旋转的操作不解释了,看下题目吧。 解题:AC自动机。大致的思路是用两个自动机,一个heap,一个b转载 2017-04-29 16:10:41 · 419 阅读 · 0 评论 -
NEFU 1267 挑战字符串 (AC自动机+贪心)好题
题意: 中文 思路: 建立 AC自动机 时记录下每个子串的长度dep 对母串进行匹配时 ans[i] 代表匹配到母串位置 i 的最大的答案 状态转移为: ans[i]=max(ans[i],ans[i-dep[rt]]+val[rt]) 代码: ans[i]=max(ans[i],ans[i-dep[rt]]+val[rt]);#include #include #inclu原创 2017-12-10 20:39:34 · 344 阅读 · 0 评论