http://acm.split.hdu.edu.cn/showproblem.php?pid=2222 #include <cstdio> #include <cstdlib> #include <cstring> + ; ; struct AC { int son[maxn][N], fail[maxn * N], endPos[maxn * N]; int t, root; int create() { ++t; ; i < N; ++i) son[t][i…
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http://blog.csdn.net/niushuai666/article/details/7002823 http://www.cppblog.com/menjitianya/archive/2014/07/10/207604.html #include<stdio.h> #include<s…
HDU 2222 Keywords search Problem : 给若干个模式串,询问目标串中出现了多少个模式串. Solution : 复习了一下AC自动机.需要注意AC自动机中的fail,和next的含义.fail指向了一个最长的与当前匹配出具有相同后缀的一个前缀节点,next用来转移下一个字符,指向最远可以匹配的位置.另外,在目标串匹配时,需要用一个temp指针不断经过fail指针向前跳转,所有经过的节点都是符合的. #include <iostream> #include <…
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…
题意: 问母串中出现多少个模式串 注意ac自动机的节点总数 #include <stdio.h> #include <string.h> #include <queue> using namespace std; inline int Max(int a,int b){return a>b?a:b;} inline int Min(int a,int b){return a>b?b:a;} int ANS; #define N 1000010 #define…
所学的AC自动机都源于斌哥和昀神的想法. 题意:求目标串中出现了几个模式串. 使用一个int型的end数组记录,查询一次. #include <cstdio> #include <cstring> #include <queue> using namespace std; const int maxw = 50 * 10000 + 10; const int sigma_size = 26; const int maxl = 1000000 + 10; struct T…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 59827    Accepted Submission(s): 19715 Problem Description In the modern time, Search engine came into the life of everybody lik…
题意: 求n个模板串在匹配串中出现了几个. SOL: 反正就是模板啦...似乎比KMP都简单----这么说似乎有点不道德...毕竟先看的KMP而他们并没有什么不同... 貌似自己的理解和他们画的图还是有些出入......不虚慢慢看... 然后就是特殊一点的一个last数组,可以比较迅速地找到包含的子串. 这个题目会出现相同的模板...没看懂老人家开map的意图,第一遍用vector打,然后这种统计数量不是直接开个num记录数量就好了吗... 然而为毛我的num比开vector还慢呢... /*=…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 70290    Accepted Submission(s): 23917 Problem Description In the modern time, Search engine came into the life of everybody lik…
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 the image, th…