题目链接: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的更多相关文章

  1. HDU 2222 AC自动机模板题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...

  2. Match:Keywords Search(AC自动机模板)(HDU 2222)

    多模匹配 题目大意:给定很多个字串A,B,C,D,E....,然后再给你目标串str字串,看目标串中出现多少个给定的字串. 经典AC自动机模板题,不多说. #include <iostream& ...

  3. HDU 3065 (AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 题目大意:多个模式串,范围是大写字母.匹配串的字符范围是(0~127).问匹配串中含有哪几种模 ...

  4. HDU 2896 (AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2896 题目大意:多个模式串.多个匹配串.其中串的字符范围是(0~127).问匹配串中含有哪几个模式串 ...

  5. HDU 2222(AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...

  6. HDU 2222 (AC自动机模板题)

    题意: 给一个文本串和多个模式串,求文本串中一共出现多少次模式串 分析: ac自动机模板,关键是失配函数 #include <map> #include <set> #incl ...

  7. hdu 2222 Keywords Search ac自动机模板

    题目链接 先整理一发ac自动机模板.. #include <iostream> #include <vector> #include <cstdio> #inclu ...

  8. KMP与AC自动机模板

    HDU 1711 Number Sequence(KMP模板题) http://acm.hdu.edu.cn/showproblem.php?pid=1711 #include<bits/std ...

  9. HDU3695(AC自动机模板题)

    题意:给你n个字符串,再给你一个大的字符串A,问你着n个字符串在正的A和反的A里出现多少个? 其实就是AC自动机模板题啊( ╯□╰ ) 正着query一次再反着query一次就好了 /* gyt Li ...

  10. POJ2222 Keywords Search AC自动机模板

    http://acm.hdu.edu.cn/showproblem.php?pid=2222 题意:给出一些单词,求多少个单词在字符串中出现过(单词表单词可能有相同的,这些相同的单词视为不同的分别计数 ...

随机推荐

  1. EHCI规范(转)

    https://blog.csdn.net/qiurihuanghua/article/details/6411640 1. EHCI 1.0规范介绍 EHCI规范为USB 2.0规范定义了一个Hos ...

  2. 非节点主机通过内网远程管理docker swarm集群

    这是今天使用 docker swarm 遇到的一个问题,终于在睡觉前解决了,在这篇随笔中记录一下. 在 docker swarm 集群的 manager 节点上用 docker cli 命令可以正常管 ...

  3. CH 3401 - 石头游戏 - [矩阵快速幂加速递推]

    题目链接:传送门 描述石头游戏在一个 $n$ 行 $m$ 列 ($1 \le n,m \le 8$) 的网格上进行,每个格子对应一种操作序列,操作序列至多有 $10$ 种,分别用 $0 \sim 9$ ...

  4. [No0000137]字符编码详解

    摘要 本文主要介绍了字符编码的基础知识,以及常见的字符编码类型,比如ASCII,Unicode,UTF-8,ISO 8859等,以及各种编码之间的关系,同时专门解释了中文字符相关的编码标准,包括GB2 ...

  5. AD采集问题

    在调试AD采集时想问的一些问题 1.电路原理图中的VSS是什么意思? 2.电路原理图中的VDD是什么意思? 3.电路原理图中的VREF+和VREF-是什么意思? 4.电路原理图中的VBAT是用来干什么 ...

  6. 《HTTP - http首部信息》

    推荐一首歌 - 僕が死のうと思ったのは (曾经我也想过一了百了) 也就听了几十遍而已 经历一番波折,终于正式到了北京. 刚开始是很艰难的,多走两步就好了,不是么. 1:首部字段 Cache-Contr ...

  7. spring+shiro+springmvc+maven权限卡控示例

    项目结构 UserController , 主要负责用户登入和注销. LinewellController, 主要负责请求受权限卡控的数据. MyRealm,自定义realm. Authorizati ...

  8. 第三方python 加密库 --- cryptography

    1,安装依赖 pip install cryptography 2,生成秘钥 from cryptography.fernet import Fernet #秘钥#随机生成秘钥 cipher_key ...

  9. 洛谷P3237 米特运输 [HNOI2014] hash/二进制分解

    正解:hash/二进制分解 解题报告: 传送门! umm首先提取下题意趴QAQ 大概是说给一棵树,每个点有一个权值,要求修改一些点的权值,使得同一个父亲的儿子权值相同,且父亲的权值必须是所有儿子权值之 ...

  10. Ansible 快速上手(转)

    add by zhj: 执行Ansible(发音时,重音在最前面)命令有两种方式,一种是ad-hoc形式,另一种是playbooks,对于软件开发者来说,一般使用ad-hoc就足够了.playbook ...