跪啃SAM

struct SAM
{
    int ch[maxn][26],size,last,pre[maxn],pos[maxn];
    SAM()
    {
        size=0;
        memset(ch[0],0,sizeof(ch[0]));
        pre[0]=-1;
    }
    int idx(char c) {return c-'A';}
    void insert(char c,int p)
    {
        int id=idx(c),x=++size;
        memset(ch[x],0,sizeof(ch[x])); pos[x]=p;
        int y=last;
        for (;y!=-1 && !ch[y][id];y=pre[y]) ch[y][id]=x;
        last=x;
        if (y==-1) pre[x]=0;
        else
        {
            if (pos[ch[y][id]]==pos[y]+1) pre[x]=ch[y][id];
            else
            {
                int z=ch[y][id],w=++size;
                memcpy(ch[w],ch[z],sizeof(ch[z]));
                pos[w]=pos[y]+1; pre[w]=pre[z];
                pre[z]=pre[x]=w;
                for (;y!=-1 && ch[y][id]==z;y=pre[y]) ch[y][id]=w;
            }
        }
    }
}sam;

不要问我为什么,大家都啃CLJ论文过来的。

怎么会有这么强的人。。发明和引进这种算法的

诶谁看懂了CLJ的论文教我下QAQ我其实还不会的

Q:后缀树中所有节点深度和是多少?

posted @ 2017-12-04 22:12  Blue233333  阅读(173)  评论(0编辑  收藏  举报