自学AC自动机
来源:互联网 发布:masta软件下载 编辑:程序博客网 时间:2024/05/01 13:30
#include <cstdio>#include <iostream>#include <cstdlib>#include <algorithm>#include <cstring>#include <queue>using namespace std ;const int ms=200*501;const int ch=200*501;const int M=100010;const int N=510;char s[M];int n,m,sum;struct Trie{ int c[ms][ch]; int value[ms],f[ms],last,[ms]; int sz; int ans[N]; Trie(){ size=1; } int idx(char c){ return (int) c; } void insert (char *s,int v){ int u=0,len=strlen (s),i,x; for (i=0;i<len;i++){ x=idx (s[i]); if (!c[u][x]){ c[u][x]=sz++; val[sz]=0; } u=c[u][x]; } val[u]=v; } void get_fail (){ queue <int> q; f[0]=0; int i,u,now,v; for (i=1;i<ch;i++){ u=c[0][i]; if (u){ f[u]=0; q.push (u); last[u]=0; } } while (!q.empty ()){ now=q.front (); q.pop (); for (i=0;i<ch;i++){ u=c[r][i]; if (!u){ c[r][i]=c[f[r]][i]; continue; } q.push (u); v=f[r]; while (v&!c[v][i]) v=f[v]; f[u]=c[v][i]; last[u]=val[f[u]] ? f[u] : last[f[u]]; } } } void print(int j){//查询并存储匹配串 ok = 1; if(j){ ans[val[j]] = 1; print(last[j]); } } void match(char *s){//模式串匹配 int len=strlen(s),j=0; int child,i; for(i=0;i<len;i++){ ch=idx(s[i]); j=c[j][child]; if(val[j]) print(j); else { if(val[last[j]]) print(last[j]); } } }}T;
0 0
- 自学AC自动机
- AC自动机...
- AC自动机
- AC 自动机
- AC自动机
- AC自动机
- ac自动机
- ac自动机
- AC自动机
- AC自动机
- AC自动机
- AC自动机
- AC自动机
- AC 自动机
- ac自动机
- AC自动机
- AC自动机
- AC自动机
- python for machine-learning
- Linux系统下安装FASTDFS STORAGE AND TRACKER
- SVN 搭建文档
- ajax上传图片
- vivado下将rtl模块做成网表加入工程使用
- 自学AC自动机
- 【程序38】 题目:写一个函数,求一个字符串的长度, 在main函数中输入字符串,并输出其长度。
- 1123. Is It a Complete AVL Tree 解析
- iOS 调用系统发短信的两种方法【原创】
- 屏幕适配
- classical binary search
- Git下的冲突解决
- Qt android opencv
- nio学习理解