#include#include#include#include#include#include#include#include#include#include

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

fzu Problem 2005 Computer Virus on Planet Pa

系統(tǒng) 1901 0

http://acm.fzu.edu.cn/problem.php?pid=2005

AC自動(dòng)機(jī) 需要優(yōu)化

否則超時(shí)

代碼:

      #include<iostream>

#include<cmath>

#include<cstdio>

#include<string>

#include<cstring>

#include<vector>

#include<stack>

#include<queue>

#include<set>

#include<map>

#include<algorithm>



#define LL long long



using namespace std;



const int INF=0x3f3f3f3f;

const int N=5500005;

const int M=255000;

const int K=26;

struct nodeTrie

{

    int v;

    int fail;

    int next[K];

    void initialize()

    {

        v=0;

        fail=-1;

        memset(next,-1,sizeof(next));

    }

}trie[M];

int cnt,root;

char s1[N];

char s[1005];

char pro[N];

int getNewNode()

{

    ++cnt;

    trie[cnt].initialize();

    return cnt;

}

void addWord(int p,char *s,int k)

{

    if(s[0]=='\0') return ;

    for(int i=0;s[i]!='\0';++i)

    {

        if(trie[p].next[s[i]-'A']==-1)

        trie[p].next[s[i]-'A']=getNewNode();

        p=trie[p].next[s[i]-'A'];

    }

    (trie[p].v)=k;

}

void init(int n)

{

    cnt=-1;

    root=getNewNode();

    for(int i=1;i<=n;++i)

    {

        gets(s);

        addWord(root,s,i);

    }

}

void bfs(int p)

{

    trie[p].fail=root;

    queue<int>qt;

    qt.push(p);

    while(!qt.empty())

    {

        int y;

        int x=qt.front();qt.pop();

        for(int i=0;i<K;++i)

        if(trie[x].next[i]!=-1)

        {

            qt.push(trie[x].next[i]);

            if(x==root)

            {trie[trie[x].next[i]].fail=root;continue;}

            y=trie[x].fail;

            while(y!=root&&trie[y].next[i]==-1)

            y=trie[y].fail;

            if(trie[y].next[i]!=-1)

            trie[trie[x].next[i]].fail=trie[y].next[i];

            else

            trie[trie[x].next[i]].fail=root;

        }

    }

}

int match(int p,char *s,int n)

{

    int wordCount=0;

    int l=0;

    while(s[l]!='\0')

    {

        while(trie[p].next[s[l]-'A']==-1&&p!=root)

        p=trie[p].fail;

        if(trie[p].next[s[l]-'A']!=-1)

        p=trie[p].next[s[l]-'A'];

        ++l;

        int fp=p;

        while(fp!=root)

        {

            if(trie[fp].v==-1)

            break;

            if(trie[fp].v>0)

            {++wordCount;}

            trie[fp].v=-1;

            fp=trie[fp].fail;

        }

        if(wordCount==n)

        break;

    }

    return wordCount;

}

int main()

{

    //freopen("data.in","r",stdin);

    int T;

    scanf("%d",&T);

    while(T--)

    {

        int n;

        scanf("%d ",&n);

        init(n);

        bfs(root);

        gets(s1);

        int m=0;

        for(int i=0;s1[i]!='\0';++i)

        if(s1[i]=='[')

        {

            int sum=0;

            for(++i;s1[i]>='0'&&s1[i]<='9';++i)

            sum=sum*10+s1[i]-'0';

            while(sum--)

            pro[m++]=s1[i];

            ++i;

        }else

        {

            pro[m++]=s1[i];

        }

        pro[m]='\0';

        //puts(pro);

        int ans=match(root,pro,n);

        reverse(pro,pro+m);

        ans+=match(root,pro,n-ans);

        printf("%d\n",ans);

    }

    return 0;

}


    

fzu Problem 2005 Computer Virus on Planet Pandora


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 国产精品福利短视在线播放频 | 奇米网狠狠| 爱人同志国语免费观看全集 | 国产精品视频网 | 欧美国产精品久久 | 无码国产精品成人午夜视频 | 国产一区在线观看免费 | 亚洲区激情区图片小说区 | 一本一道久久综合狠狠老 | 久久一区 | 99久久亚洲精品日本无码 | 成人不卡 | 欧美久久久久久 | 中文字幕在线精品 | 四虎精品8848ys一区二区 | 色综合亚洲精品激情狠狠 | 黄色大片在线播放 | 无遮挡羞羞视频 | 久久精品国产99国产精品澳门 | 91在线免费视频 | 粉嫩粉嫩芽的虎白女18在线视频 | 91久久综合九色综合欧美亚洲 | 日韩在线观看一区二区不卡视频 | 亚洲一区二区免费视频 | 欧美日批视频 | 摸金校尉之九幽将军 | 91久久精品久久国产性色也91 | 午夜精品亚洲 | 亚洲成网 | 午夜刺激视频 | 日本aⅴ在线 | 免费观看日韩大尺码观看 | 黄色网址在线视频 | 野花国产精品入口 | 欧美成人18性 | 97av视频在线播放 | 亚洲成a人片在线网站 | 国产成人综合久久精品红 | 久草中文在线 | 黄色a视频 | 999精品久久久 |