【HDOJ】2222 Keywords Search】的更多相关文章

AC自动机基础题. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <queue> using namespace std; #define MAXL 1000005 #define TRIEN 26 ]; typedef struct Trie { int n; Trie *fail; Trie *next[TRIEN];…
[算法]AC自动机 [题解]本题注意题意是多少关键字能匹配而不是能匹配多少次,以及可能有重复单词. 询问时AC自动机与KMP最大的区别是因为建立了trie,所以对于目标串T与自动机串是否匹配只需要直接访问对应结点,而不用真的比较. 因此可以预处理出拥有对应节点的失配串,不用一次一次跑前跑去找一样的. 然后还有就是一个结点可能对应多个串,所以需要last使统计答案完整. AC自动机的细节标注在代码里了. AC自动机过程: [trie] for 长度 if(!ch[u][c])初始化,ch[u][c…
题目 传送门:QWQ 分析 $ AC $自动机模板,黈力的码风真的棒极了,这是我抄他的. 还有 题号不错 代码 #include <cstdio> #include <cstring> #define N 500007 using namespace std; ],fail[N],cur,j,end[N],q[N],vis[N],ans[N],end2[N],end3[N]; ]; int find(int cur,int i){ if(!cur)return rt; if(son…
PE的注意,如果没有满足条件的不输出空格.简单模拟,暴力解. /* */ #include <iostream> #include <sstream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <deque> #include…
显然适用字典树建树,串长和模式串都很小,所以直接递归搜索.同时,适用bk标记当前的查询次数(排除不同模式的多次查询成功,如*t*).需要主要的是,居然存在同名文件!!!. /* 2279 */ #include <iostream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <vector&…
题目链接 题意:每个文本串的出现次数 分析:入门题,注意重复的关键字算不同的关键字,还有之前加过的清零.   新模板,加上last跑快一倍 #include <bits/stdc++.h> struct AC { static const int NODE = 10000 * 50 + 5; static const int SIZE = 26; int ch[NODE][SIZE], fail[NODE], last[NODE]; int end[NODE]; int sz; void cl…
HDU 2222 Keywords Search(查询关键字) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) [Description] [题目描述] In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiskey also wants to br…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 44687    Accepted Submission(s): 14103 Problem Description In the modern time, Search engine came into the life of everybody li…
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 t…
Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 59360    Accepted Submission(s): 19520 Problem Description In the modern time, Search engine came into the life of everybody lik…