• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            #include <iostream>
            #include 
            <queue>

            using namespace std;

            struct Trie{
                
            int    cnt;
                Trie
            *  next[26], *prefix;
            }
            Table[500000];

            int   index= 0;
            Trie
            * root;
            char  str[1000001];

            void init(){
                index
            = 0;
                root
            = &Table[index];
                memset( Table[
            0].next, 0sizeof(Table[0].next) );
                Table[
            0].cnt= 0; Table[0].prefix= NULL;
            }


            void insert( char* s )
            {
                Trie
            * r= root;
                
            while*s ){
                    
            int t= *s- 'a';
                    
            if!r->next[t] ){
                        
            ++index;
                        memset( Table[index].next, 
            0sizeof(Table[index].next) );
                        Table[index].cnt
            = 0; Table[index].prefix= NULL;
                        r
            ->next[t]= &Table[index];
                    }

                    r
            = r->next[t]; s++;
                }
                
                r
            ->cnt++;
            }


            void get_prefix()
            {
                Trie
            * r= root;
                queue
            <Trie*> q;
                q.push( root ); root
            ->prefix= NULL;
                
                
            while!q.empty() ){
                    Trie
            * father= q.front(); q.pop();
                    
            forint i= 0; i< 26++i )
                    
            if( father->next[i] ){
                        Trie
            * tmp= father->prefix;
                        
            while( tmp && !tmp->next[i] ) tmp= tmp->prefix;
                        
            if!tmp ) father->next[i]->prefix= root;
                        
            else       father->next[i]->prefix= tmp->next[i];
                        
                        q.push( father
            ->next[i] );
                    }

                }

            }


            int ac_run(){
                Trie
            * p= root;
                
            int ans= 0;
                
            char* s= str;
                
            while*s ){
                    
            int t= *s- 'a';
                    
            while!p->next[t] && p!= root ) p= p->prefix;
                    p
            = p->next[t];
                    
            if!p ) p= root;
                    Trie
            * tp= p;
                    
            while( tp!= root && tp->cnt!= -1 ){
                        ans
            += tp->cnt; 
                        tp
            ->cnt= -1
                        tp
            = tp->prefix;}

                    s
            ++;
                }

                
            return ans;
            }


            int main()
            {
                
            int test;
                scanf(
            "%d",&test );
                
            while( test-- )
                
            {
                    
            int n; char s[55];
                    scanf(
            "%d",&n ); init(); getchar();
                    
            forint i= 0; i< n; ++i ){
                        gets(s); insert(s); }

                    gets(str); get_prefix();
                    printf(
            "%d\n", ac_run() );    
                }

                
                
            return 0;
            }

            posted on 2009-04-15 14:17 Darren 閱讀(382) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            日韩电影久久久被窝网| 精品综合久久久久久98| 久久黄视频| 久久精品国产第一区二区| 国产午夜久久影院| 久久免费视频观看| 国产成人精品综合久久久| 日韩精品无码久久一区二区三| 国内精品久久久久久久久电影网| 久久本道久久综合伊人| 韩国三级中文字幕hd久久精品| 久久精品国产亚洲精品| 久久久人妻精品无码一区| 97久久国产露脸精品国产| 精品无码久久久久久尤物| 国内精品久久久久久久亚洲| 久久精品国产亚洲Aⅴ蜜臀色欲| 久久久久久亚洲精品无码| 日产精品久久久久久久| 91超碰碰碰碰久久久久久综合| 国产精品久久久久久久人人看 | 久久婷婷色综合一区二区| 久久无码AV中文出轨人妻| www久久久天天com| 久久久久亚洲AV成人网| 亚洲精品无码久久久久去q| 国产一区二区三区久久| 久久精品二区| 久久久无码精品亚洲日韩按摩| 久久综合视频网站| 热re99久久精品国99热| 久久久国产亚洲精品| 久久天堂电影网| 久久久这里只有精品加勒比| 久久91综合国产91久久精品| 久久久这里有精品中文字幕| 无码精品久久久天天影视| 久久精品视频91| 久久国产精品99久久久久久老狼| 久久久网中文字幕| 国产精品福利一区二区久久|