HDU 2222 : Keywords Search
发布日期:2021-06-30 16:05:52
浏览次数:2
分类:技术文章
本文共 774 字,大约阅读时间需要 2 分钟。
学习了字典树之后,来学一下AC自动机,其实挺简单的,但是很强大
这是一道AC自动机模板题 AC自动机学习博客:我的代码:
#include#include using namespace std;const int maxn=500000+100;int trie[maxn][26],sum[maxn],fail[maxn],tot;int que[maxn];inline void insert(char* ch){ int len=strlen(ch); int root=0; for(int i=0;i =0){ cnt+=sum[node_tmp]; sum[node_tmp]=-1; } else break; node_tmp=fail[node_tmp]; } } } return cnt;}inline void init(){ tot=0; memset(trie,0,sizeof(trie)); memset(sum,0,sizeof(sum)); memset(fail,0,sizeof(fail));}char str[maxn*2];int main(){ int T,n; scanf("%d",&T); while(T--){ init(); scanf("%d",&n); getchar(); char ch[100]; for(int i=1;i<=n;i++){ scanf("%s",ch); insert(ch); } build_fail(); scanf("%s",str); printf("%d\n",search(str)); }}
转载地址:https://kaven.blog.csdn.net/article/details/81169791 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
很好
[***.229.124.182]2024年04月25日 12时51分14秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
依赖错误
2019-05-01
ROS安装与卸载
2019-05-01
安装openrave 0.9的各种依赖包
2019-05-01
trajopt代码使用
2019-05-01
kpm代码使用细节
2019-05-01
redis
2019-05-01
@FeignClient注解的重复名称解决
2019-05-01
ClassFile之Methods
2019-05-01
java.net.BindException: 无法指定被请求的地址
2019-05-01
scala list
2019-05-01
k8s设置阿里云仓库
2019-05-01
svn服务器安装
2019-05-01
spark 笔记1
2019-05-01
svn 没有作者信息) | (没有时间信息
2019-05-01
shell dirname basename
2019-05-01
未来已至,5G加持下的云游戏将走向何方?
2019-05-01
闭关三月!猛男逆道而行,四杀斩获阿里 / 腾讯 / 京东 / 百度等大厂 offer
2019-05-01
【linux用户模块】用户/用户组的管理
2019-05-01
计算机网络 —— 网络层 1.
2019-05-01