#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=*+;
struct node{
int son[],f,v,cnt;
void rnw(){memset(son,,sizeof(son));f=v=cnt=;}
}ch[maxn];
char s[],t[];
int tot,q[maxn],head,tail,T,n;
void add(char s[]){
int u=,len;
len=strlen(s);
for(int i=;i<len;++i){
int c=s[i]-'a';
if(!ch[u].son[c]){ch[u].son[c]=++tot;}
u=ch[u].son[c];
}
ch[u].cnt++;
}
void pre(){
head=tail=;
ch[].f=;
for(int i=;i<;++i){
int u=ch[].son[i];
if(u){
ch[u].f=;
q[++tail]=u;
}
}
while(head<tail){
int now=q[++head];
for(int i=;i<;++i){
int u=ch[now].son[i];
if(!u){
ch[now].son[i]=ch[ch[now].f].son[i];
continue;
}
q[++tail]=u;
int v=ch[now].f;
while(v&&!ch[v].son[i])v=ch[v].f;
ch[u].f=ch[v].son[i];
}
}
}
ll solve(char t[]){
ll res=;
int len,u=;
len=strlen(t);
for(int i=;i<len;++i){
int c=t[i]-'a';
u=ch[u].son[c];
//if(ch[u].cnt){
int tmp=u;
while(tmp){
if(ch[tmp].cnt>=){
res+=ch[tmp].cnt;
ch[tmp].cnt=-;
}
else{break;}
tmp=ch[tmp].f;
}
//}
}
return res;
}
int main(){
cin>>T;
while(T--){
tot=;
for(int i=;i<=;++i)ch[i].rnw();
scanf("%d",&n);
for(int i=;i<=n;++i){
scanf("%s",s);add(s);
}
scanf("%s",t);
pre();
printf("%lld\n",solve(t));
}
system("pause");
return ;
}
/*
1
2
abcdefgh
efg
abcdefgh
*/

PS:那个注释掉的if不能加,这个串就算不是一个结尾也要往前跳,hack数据就写在下面。

hdu2222(ac自动机模板)的更多相关文章

  1. [hdu2222] [AC自动机模板] Keywords Search [AC自动机]

    AC自动机模板,注意!ch,Fail,lab数组的大小不是n而是节点个数,需要认真计算! #include <iostream> #include <algorithm> #i ...

  2. Keywords Search HDU2222 AC自动机模板题

    ac自动机说起来很复杂,其实和kmp是一样的思路,都是寻找相同前后缀,减少跳的次数.只要理解了kmp是怎么求next数组的,ac自动机bfs甚至比knp还好写. 这里大致说一下kmp求next数组的方 ...

  3. Hdu 5384 Danganronpa (AC自动机模板)

    题目链接: Hdu 5384 Danganronpa 题目描述: 给出n个目标串Ai,m个模式串Bj,问每个目标串中m个模式串出现的次数总和为多少? 解题思路: 与Hdu 2222  Keywords ...

  4. HDU 2222 AC自动机模板题

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

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

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

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

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

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

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

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

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

  9. HDU2222 (AC自动机)

    AC自动机模板题. 被卡内存了 死活A不掉.. AC自动机参考教程: http://www.cppblog.com/menjitianya/archive/2014/07/10/207604.html ...

随机推荐

  1. .netcore webapi 在startup中读取配置字符串

    参考微软官方说明:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration 具体为: 读取方法见下图中标红的格式, ...

  2. mysql 安装后出现 10061错误

    #服务器端  提示 The vervice already exists! The current server installed #mysqld 服务没有启动 解决办法 移除原来的mysql服务  ...

  3. Jmeter常用脚本开发之Beanshell Sampler

    Beanshell Sampler Beanshell介绍:是一种完全符合java语法规范的脚本语言,且又拥有自己的一些语法和方法:是一种松散类型的脚本语言:它执行标准java语句和表达式,另外它还包 ...

  4. Ionic3--数据存储

    1.使用sqlite cordova plugin add cordova-sqlite-storage --save npm install --save @ionic/storage (本地存储) ...

  5. HTML JavaScript练习

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. [转载] Linux中的搜索文件命令

    搜索文件用处很大,我们往往需要知道一个文件存放在什么地方,我们又知道Linux是命令强大的一个系统,所以也有好多非常优秀的搜索命令.通常find不常用,因为速度慢,耗费硬盘空间.通常我们先使用wher ...

  7. PID参数调节口诀

    参数整定找最佳, 从小到大顺序查. 先是比例后积分, 最后再把微分加. 曲线振荡很频繁, 比例度盘要放大. 曲线漂浮绕大弯, 比例度盘往小扳. 曲线偏离回复慢, 积分时间往下降. 曲线波动周期长, 积 ...

  8. Web 文件上传方面的安全问题

    一. 文件上传漏洞与WebShell的关系 文件上传漏洞是指网络攻击者上传了一个可执行的文件到服务器并执行.这里上传的文件可以是木马,病毒,恶意脚本或者WebShell等.这种攻击方式是最为直接和有效 ...

  9. [SoapUI] Property Expansion in soapUI

    1. Property Expansion in soapUI SoapUI provides a common syntax to dynamically insert ("expand& ...

  10. [AI]神经网络章2 神经网络中反向传播与梯度下降的基本概念

    反向传播和梯度下降这两个词,第一眼看上去似懂非懂,不明觉厉.这两个概念是整个神经网络中的重要组成部分,是和误差函数/损失函数的概念分不开的. 神经网络训练的最基本的思想就是:先“蒙”一个结果,我们叫预 ...