摘要: 题意:给定n个单词(均为大写字母)和一个文本(均为可见字符),求每个单词在文本中出现的次数。单词数不超过1000,长度不超过50,文本长度不超过2000000分析:AC自动机基础题。一个小的优化:由于单词均为大写字母,所以建字典树时第二维大小可以只开26,这样可以节约时间和空间,在扫描文本时(均为可见字符),碰到非大写字母时,直接将指针指向根结点,继续扫描下一个字符即可。View Code #include <stdio.h>#include <string.h>#include <queue>using namespace std;#define LEN 阅读全文
posted @ 2012-07-31 21:43 BeatLJ 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 题意:给n个单词和一个文本,求有多少个单词出现在文本中。据说这题是AC自动机的模版题。这题也是我写的第一个AC自动机的题。View Code #include <stdio.h>#include <string.h>#include <queue>using namespace std;#define LEN 55#define N 10010int n,node;int next[N*LEN][26];int cnt[N*LEN];int fail[N*LEN];void init(){ memset(next[0],0,sizeof(next[0])); 阅读全文
posted @ 2012-07-31 17:16 BeatLJ 阅读(209) 评论(0) 推荐(0) 编辑