AC自动机模板1
题目链接:https://www.luogu.org/problemnew/show/P3808
要注意的是一定要把len赋值strlen(s);不然超时超的自闭!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define P pair<int,int>
const int N=1e6+;
void read(int &a)
{
a=;
int d=;
char ch;
while(ch=getchar(),ch>''||ch<'')
if(ch=='-')
d=-;
a=ch-'';
while(ch=getchar(),ch>=''&&ch<='')
a=a*+ch-'';
a*=d;
}
void write(int x)
{
if(x<)
putchar(),x=-x;
if(x>)
write(x/);
putchar(x%+'');
}
struct note
{
int to[],bz,nex;
}trie[N];
int tot;
char s[N];
void ins(char *s)
{
int t=;
int len=strlen(s);
for(re int i=;i<len;i++)
{
int x=s[i]-;
if(!trie[t].to[x])
trie[t].to[x]=++tot;
t=trie[t].to[x];
}
trie[t].bz++;
}
void built()
{
queue <int> q;
for(re int i=;i<=;i++)
if(trie[].to[i])
trie[trie[].to[i]].nex=,q.push(trie[].to[i]);
while(!q.empty())
{
int p=q.front();
q.pop();
for(re int i=;i<=;i++)
if(trie[p].to[i])
trie[trie[p].to[i]].nex=trie[trie[p].nex].to[i],q.push(trie[p].to[i]);
else
trie[p].to[i]=trie[trie[p].nex].to[i];
}
}
int solve(char *s)
{
int ans=,now=;
int len=strlen(s);
for(re int i=;i<len;i++)
{
now=trie[now].to[s[i]-'a'+];
for(re int j=now;j&&trie[j].bz!=-;j=trie[j].nex)
ans+=trie[j].bz,trie[j].bz=-;
}
return ans;
}
int main()
{
int n;
read(n);
while(n--)
{
scanf("%s",s);
ins(s);
}
trie[].nex=;
built();
scanf("%s",s);
cout<<solve(s)<<endl;
return ;
}
AC自动机模板1的更多相关文章
- HDU 2222 AC自动机模板题
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...
- Match:Keywords Search(AC自动机模板)(HDU 2222)
多模匹配 题目大意:给定很多个字串A,B,C,D,E....,然后再给你目标串str字串,看目标串中出现多少个给定的字串. 经典AC自动机模板题,不多说. #include <iostream& ...
- HDU 3065 (AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 题目大意:多个模式串,范围是大写字母.匹配串的字符范围是(0~127).问匹配串中含有哪几种模 ...
- HDU 2896 (AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2896 题目大意:多个模式串.多个匹配串.其中串的字符范围是(0~127).问匹配串中含有哪几个模式串 ...
- HDU 2222(AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...
- HDU 2222 (AC自动机模板题)
题意: 给一个文本串和多个模式串,求文本串中一共出现多少次模式串 分析: ac自动机模板,关键是失配函数 #include <map> #include <set> #incl ...
- hdu 2222 Keywords Search ac自动机模板
题目链接 先整理一发ac自动机模板.. #include <iostream> #include <vector> #include <cstdio> #inclu ...
- KMP与AC自动机模板
HDU 1711 Number Sequence(KMP模板题) http://acm.hdu.edu.cn/showproblem.php?pid=1711 #include<bits/std ...
- HDU3695(AC自动机模板题)
题意:给你n个字符串,再给你一个大的字符串A,问你着n个字符串在正的A和反的A里出现多少个? 其实就是AC自动机模板题啊( ╯□╰ ) 正着query一次再反着query一次就好了 /* gyt Li ...
- POJ2222 Keywords Search AC自动机模板
http://acm.hdu.edu.cn/showproblem.php?pid=2222 题意:给出一些单词,求多少个单词在字符串中出现过(单词表单词可能有相同的,这些相同的单词视为不同的分别计数 ...
随机推荐
- mysql中将查询结果进行拼接处理及concat、group_concat的使用
说明: 本文中使用的例子均在下面的数据库表tt2下执行: 一.concat()函数1.功能:将多个字符串连接成一个字符串. 2.语法:concat(str1, str2,...) 返回结果为连接参数产 ...
- 通过Docker构建TensorFlow Serving
最近在用Docker搭建TensorFlow Serving, 在查阅了官方资料后,发现其文档内有不少冗余的步骤,便一步步排查,终于找到了更简单的Docker镜像构建方法.这里有两种方式: 版本一: ...
- Haproxy的三种保持客户端会话保持方式
2017-03-25 15:41:41 haproxy 三种保持客户端Seesion; 一.源地址hash(用户IP识别) haroxy 将用户IP经过hash计算后 指定到固定的真实服务器上(类 ...
- win10 SVN不能显示图标
参考的解决办法有很多(http://blog.csdn.net/lishehe/article/details/8257545),大多数是操作一下注册表. 我就按照他们的办法,svn的注册表顺序根本上 ...
- 解决GP服务产生的结果无法自动发布为地图服务的问题
在ArcGIS for Javascript API或REST API调用GP服务时,常常会遇到这样一种情况:GP服务运行以后,执行成功,也能够生成结果,然而结果并没有直接产生动态的地图服务供API调 ...
- windows共享文件分析
·小结: 1.win+r,\\ip 弹出登录框,输入Guest,密码空登录:前置检查来宾账户状态: 2.net use 查看当前已经连接到的主机 实践: C:\Users\sas>net u ...
- extundelete fuser
[extundelete ] fuser -mv /dev/sda6 https://blog.csdn.net/xwl145/article/details/38896699 多列排序[sort]h ...
- knowledge learning things TODO
加密分区 suricata调研 tor配置 tilda配置 automake / autoconf / libtool 使用 大页内存的深入原理 Memory channels Network Man ...
- kafka实战读书笔记
1.katka_2.12-l.0.0.tgz 上面两个文件中的 2.11 /2.12 分别表示编译 Kafka 的 Scala 语言版本,后面的 1.0 .0 是 Kafka的版本 . 2.kafka ...
- DevOps理论与实践总结
DevOps指导理论与实践 [第01篇]:郭宏泽:全开源架构下的DevOps实践(转) SonarQube应用指南 [第一篇]:SonarQube Scanner报svn: E170001错误 che ...