博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu2222-AC自动机
阅读量:7030 次
发布时间:2019-06-28

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

#include
#include
#include
#include
#include
using namespace std;#define N 26#define maxn 500005struct Trie{ int next[500010][26],fail[500010],end[500010]; int root,L; int newnode() { for(int i=0;i<26;i++) next[L][i]=-1; end[L++]=0; return L-1; } void init() { L=0; root=newnode(); } void insert(char buf[]) { int len=strlen(buf); int now=root; for(int i=0;i
Q; fail[root]=root; for(int i=0;i<26;i++) { if(next[root][i]==-1) { next[root][i]=root; }else { fail[next[root][i]]=root; Q.push(next[root][i]); } } while(!Q.empty()) { int now=Q.front(); Q.pop(); for(int i=0;i<26;i++) { if(next[now][i]==-1) { next[now][i]=next[fail[now]][i]; } else { fail[next[now][i]]=next[fail[now]][i]; Q.push(next[now][i]); } } } } int query(char buf[]) { int len=strlen(buf); int now=root; int res=0; for(int i=0;i

 找到的模板,不错不错。

转载于:https://www.cnblogs.com/dancer16/p/7241984.html

你可能感兴趣的文章
js实现倒计时
查看>>
C#保存文件为无BOM的utf8格式
查看>>
MVC、MVP以及MVVM分析
查看>>
解决Android Studio 错误方法
查看>>
kindeditor用法简单介绍
查看>>
bson.errors.InvalidStringData: strings in documents must be valid UTF-8
查看>>
浅析Java中的访问权限控制
查看>>
Topological Sorting
查看>>
这个是我们公司的面试题。 特此共享
查看>>
【每日算法】排序算法总结(复杂度&amp;稳定性)
查看>>
JavaWeb学习总结(十三)——使用Session防止表单重复提交(转)
查看>>
tushare
查看>>
【ZT】Oracle CASE WHEN 用法介绍
查看>>
LeetCode--028--实现strStr() (java)
查看>>
LeetCode--027--移除元素
查看>>
matlab练习程序(渲染三原色)
查看>>
slice splice substr substring
查看>>
NSIS检测操作系统x64还是x86的问题。
查看>>
Player 启动提示 Had errors initializing network: Can't Bind Socket
查看>>
poj - 1655 Balancing Act
查看>>