您的位置:首页 > 其它

AC自动机模板

2016-03-02 15:49 375 查看
啦啦啦二十分钟默出来编译通过,一会去试几道题好啦

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 10005;
const int maxm = 100;
int n, tot, temp;
int ch[maxn][maxm], fail[maxn], flag[maxn], q[maxn];
int cal(char c)
{
return c-'a';
}
void newnode(int x,int temp)
{
ch[x][temp] = ++tot;
//还有别的我懒得写2333333
}
void addtrie(char s[])
{
int x = 0, p = 0;
int len = strlen(s);
while( p < len )
{
temp=cal(s[p]);
if( !ch[x][temp] ) newnode(x, temp);
x = ch[x][temp];
p++;
}
flag[x] = true;
}
void getfail(void)
{
int h = 0, t = 0;
for(int i = 0; i < maxm; i++)
if( ch[0][i] ) q[t++] = ch[0][i];
while( h < t )
{
temp=q[h++];
//flag[temp]|=flag[fail[temp]];
for(int i = 0; i < maxm; i++)
if( !ch[temp][i] ) ch[temp][i] = ch[fail[temp]][i];
else
{
q[t++] = ch[temp][i];
fail[ch[temp][i]] = ch[fail[temp]][i];
}
}
}
int main(void)
{
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: