AC自动机模板

来源:互联网 发布:js用数字图片表示时间 编辑:程序博客网 时间:2024/06/06 12:31

啦啦啦二十分钟默出来编译通过,一会去试几道题好啦

#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;}
0 0
原创粉丝点击