博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2896 病毒侵袭 (AC自动机)
阅读量:7077 次
发布时间:2019-06-28

本文共 1088 字,大约阅读时间需要 3 分钟。

与HDU2222差不多。。

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 int n,m; 9 char s[100005];10 struct Trie{11 int fail[200005],used[10005],end[200005],next[200005][130],L,root;12 int newnode(){13 for (int i=0;i<=128;i++)14 next[L][i]=-1;15 end[L++]=-1;16 return L-1;17 } 18 void clear(){19 L=0;root=newnode();20 }21 void insert(char s[],int id){22 int now=root,len=strlen(s);23 for (int i=0;i
Q;31 int now=root;32 for (int i=0;i<=128;i++)33 if (next[root][i]==-1) next[root][i]=root;34 else{35 fail[next[root][i]]=root;36 Q.push(next[root][i]);37 }38 while (!Q.empty()){39 int now=Q.front();40 Q.pop();41 for (int i=0;i<=128;i++){42 if (next[now][i]==-1)43 next[now][i]=next[fail[now]][i];44 else{45 fail[next[now][i]]=next[fail[now]][i];46 Q.push(next[now][i]);47 } 48 }49 } 50 }51 bool query(char s[],int n,int id){52 int len=strlen(s);53 int now=root;54 memset(used,0,sizeof used);55 bool flag=false;56 for (int i=0;i

 

转载于:https://www.cnblogs.com/qzqzgfy/p/5551735.html

你可能感兴趣的文章
数据结构和算法
查看>>
SQL基本编程,分支语句,循环语句,存储过程,触发器
查看>>
软件测试2019:第三次作业
查看>>
NOIP2018 游记
查看>>
luoguP4647 [IOI2007] sails 船帆
查看>>
C#读写文本和连接数据库
查看>>
浮点数值的表示
查看>>
winform窗体取消最大化双击标题最大化
查看>>
[cogs2652]秘术「天文密葬法」
查看>>
前端之移动页面布局
查看>>
Computer Vision Algorithm Implementations
查看>>
2013年
查看>>
ImageLoader
查看>>
css 选择符中的 >,+,~,=,^,$,*,|,:,空格 的意思
查看>>
白话数字签名(3)——Web程序中的数字签名(转)
查看>>
使用javascript连接mqtt协议(自动重连问题)
查看>>
bzoj2337
查看>>
并查集(Union-Find)算法介绍
查看>>
Codeforces 1097 Alex and a TV Show
查看>>
struts2的验证框架
查看>>