https://vjudge.net/problem/UVALive-4670 中文题面:https://www.luogu.org/problem/show?pid=3796 AC自动机模板 注意如果有重复字符串,要输出所有的重复字符串 可以用重复字符串中标号最小的字符串来表示所有的重复字符串 例: aba abba aba aba出现了2次, 令mp[1]=mp[3]=1 代码实现的话,只需要在insert的最后判断, 如果这个单词节点还没有标记,标记上这个单词的编号 如果有标记,令当前单词…
UVAlive 4670 Dominating Patterns 题目:   Dominating Patterns   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description The archaeologists are going to decipher a very mysterious ``language". Now, they kno…
题意:多个模板串,一个文本串,求出那些模板串在文本串中出现次数最多. 解法:AC自动机入门模板题. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <string> #include <vector> #in…
在文本串中找出现次数最多的子串. 思路:AC自动机模板+修改一下print函数. #include<stdio.h> #include<math.h> #include<stdio.h> #include<stdlib.h> #include<iostream> #include<string> #include<memory.h> #include<map> #include<queue> usi…
input n 1<=n<=150 word1 word2 ... wordn 1<=len(wirdi)<=70 s 1<=len(s)<=1000000 output 最多出现次数 出现最多的串,按输入顺序输出,可能出现相同串,也要输出 做法:用一个end数组记下每个串结尾的字符的下标,对应val为1,每次找到就将val++,然后找到最大的val,输出最大val对应的字符串 #include <cstdio> #include <queue>…
题目链接:简单版,增强版 简单版: #include <cstdio> #include <cstring> const int N=1e6+5,S=26; char s[N]; struct AC_Automaton { int cnt,q[N],val[N],fail[N],las[N],son[N][S]; // struct Node // { // int val,las,fail,son[S]; // Node *son[S];//指针太麻烦了.. // Node()…
AC自动机的裸题.学了kmp和Trie以后不难看懂. 有一些变化,比如0的定义和f的指向,和建立失配边,以及多了后缀连接数组last.没有试过把失配边直接当成普通边(一开始还是先这样写吧). #include<bits/stdc++.h> using namespace std; , maxnds = *+, sigma_size = , maxsubs = ; char str[maxlen]; #define idx(x) x-'a'; int last[maxnds];//后缀连接 为0…
题目:https://www.luogu.org/problemnew/show/P3804 模仿了一篇题解,感觉很好写啊. 代码如下: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; ; ,cnt=,go[xn][],fa[xn],l[xn],siz[xn],tax[xn],a[xn]; char s[xn]; void…
题目:P3808:https://www.luogu.org/problemnew/show/P3808 P3796:https://www.luogu.org/problemnew/show/P3796 从这里学了下AC自动机:http://www.cnblogs.com/cjyyb/p/7196308.html 我的理解大概就是构建一棵由模式串组成的 Trie 树,然后把文本串一节一节放在上面查找: 失配指针指向的是结尾字母和自己一样的.Trie 树上的其他分支,大约就是在找后缀这样的感觉:…
题目链接 //删掉一个单词需要前移一段位置,用链表维护就好了 复杂度O(sum(len)) #include <cstdio> #include <cstring> #define S 26 const int N=1e5+7; int n; char s[N],p[N]; struct AC_Automaton { int cnt,son[N][S],fail[N],pos[N],q[N],dep[N]; bool val[N]; struct List { int l,r; }…