啦啦啦二十分钟默出来编译通过,一会去试几道题好啦
#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;
}