• <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>

            學習心得(code)

            superlong@CoreCoder

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              74 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

            公告

            文字可能放在http://blog.csdn.net/superlong100,此處存放代碼

            常用鏈接

            留言簿(4)

            我參與的團隊

            搜索

            •  

            最新隨筆

            最新評論

            • 1.?re: Poj 1279
            • 對于一個凹多邊形用叉積計算面積 后能根據結果的正負來判斷給的點集的時針方向?
            • --bsshanghai
            • 2.?re: Poj 3691
            • 你寫的這個get_fail() 好像并是真正的get_fail,也是說fail指向的串并不是當前結點的子串。為什么要這樣弄呢?
            • --acmer1183
            • 3.?re: HDU2295[未登錄]
            • 這個是IDA* 也就是迭代加深@ylfdrib
            • --superlong
            • 4.?re: HDU2295
            • 評論內容較長,點擊標題查看
            • --ylfdrib
            • 5.?re: HOJ 11482
            • 呵呵..把代碼發在這里很不錯..以后我也試試...百度的編輯器太爛了....
            • --csuft1

            閱讀排行榜

            評論排行榜

             

            # include <stdio.h>
            # include 
            <string.h>

            struct tree {
                tree 
            *next[4], *fail;
                
            int state, flag;
            }
            ;

            tree sta[
            505];
            int indexx;
            int map[255];
            int power[4], times[4];

            tree 
            *root, *p;

            void newn() {
                sta[indexx].fail 
            = NULL;
                sta[indexx].flag 
            = 0;
                sta[indexx].state 
            = indexx;
                
            for(int i = 0; i < 4; i ++) sta[indexx].next[i] = 0;
            }


            void init() {
                indexx 
            = 0;
                newn();
                root 
            = &sta[indexx ++];
                map[
            'A'= 0; map['C'= 1; map['G'= 2; map['T'= 3;
            }


            void insert(char ch[]) {
                
            int id, i = 0;
                p 
            = root;
                
            while(ch[i]) {
                    id 
            = map[ch[i]];
                    
            if(!p->next[id]) {
                        newn();
                        p
            ->next[id] = &sta[indexx++];
                    }

                    p 
            = p->next[id];
                    i 
            ++;
                }

                p
            ->flag ++;
            }


            tree 
            *que[10001];

            void get_fail() {
                
            int close = -1, open = 0, i;
                p 
            = root; p->fail = root;
                que[
            0= root;
                
            while(close < open) {
                    p 
            = que[++close];
                    
            for(int i = 0; i < 4; i ++{
                        
            if(p->next[i] == 0{
                            
            if(p == root)    p->next[i] = root;
                            
            else            p->next[i] = p->fail->next[i];
                        }
             else {
                            
            if(p == root)    p->next[i]->fail = root;
                            
            else {
                                p
            ->next[i]->fail = p->fail->next[i];
                                p
            ->next[i]->flag += p->fail->next[i]->flag;
                            }

                            que[
            ++open] = p->next[i];
                        }

                    }

                }

            }



            int f[5005][15005], num[4], tot;

            void dfs(int s, int deep) {
                
            if(deep == 4{
                    
            for(int i = 0; i < indexx; i ++)
                        f[i][s] 
            += sta[i].flag;
                    
            for(int i = 0; i < indexx; i ++)
                        
            for(int j = 0; j < 4; j ++)
                            
            if( num[j] != times[j] && f[i][s + power[j]] < f[sta[i].next[j]->state][s] )
                                f[i][s 
            + power[j]] = f[sta[i].next[j]->state][s];
                }
             else {
                    
            for(int i = 0; i <= times[deep]; i ++{
                        num[deep] 
            = i;
                        dfs(s, deep 
            + 1);
                        s 
            += power[deep];
                    }

                }

            }


            int dp() {
                
            char str[40];
                
            int L;
                scanf(
            "%s", str);
                L 
            = strlen(str);
                memset(times, 
            0sizeof(times));
                
            for(int i = 0; i < L; i ++{
                    times[map[str[i]]] 
            ++;
                }

                power[
            3= 1;
                
            for(int i = 2; i >= 0; i --{
                    power[i] 
            = power[i+1* (times[i+1+ 1);
                }

                tot 
            = power[0* (times[0+ 1);
                
            for(int i = 0; i < indexx; i ++)
                    
            for(int j = 0; j < tot; j ++) f[i][j] = 0;
                dfs(
            0 ,0);
                
            int ans = f[0][tot-1];
                
            return ans;
            }


            int n;
            char dic[50][11];

            int main() {
                
            int t = 0;
                
            while(scanf("%d"&n), n) {
                    init();
                    
            for(int i = 0; i < n; i ++{
                        scanf(
            "%s", dic[i]);
                        insert(dic[i]);
                    }

                    get_fail();
                    
            int ans = dp();
                    printf(
            "Case %d: %d\n",++t, ans);
                }

            }

            posted on 2010-03-22 11:14 superlong 閱讀(302) 評論(0)  編輯 收藏 引用
            久久精品无码午夜福利理论片| 91麻精品国产91久久久久| 无码8090精品久久一区| 亚洲国产成人精品91久久久 | 中文字幕久久久久人妻| 久久精品中文騷妇女内射| 久久国产精品久久| 久久亚洲中文字幕精品一区四| 欧美亚洲色综久久精品国产| 色综合久久最新中文字幕| 四虎影视久久久免费观看| 精品国产乱码久久久久久1区2区 | 国产精品久久久久久久久久免费| 久久久中文字幕日本| 久久亚洲AV成人出白浆无码国产| 国产精品亚洲综合专区片高清久久久| 亚洲精品无码久久久| 欧美久久综合性欧美| 一本色综合网久久| 热RE99久久精品国产66热| 久久成人影院精品777| 亚洲精品乱码久久久久久| 久久久久人妻一区精品果冻| 国产精品久久99| 亚洲级αV无码毛片久久精品| 九九久久精品国产| 久久久久久久尹人综合网亚洲| 亚洲午夜久久久久久噜噜噜| 久久久无码精品亚洲日韩软件| 9999国产精品欧美久久久久久 | 国产69精品久久久久99| 久久久久高潮毛片免费全部播放| 武侠古典久久婷婷狼人伊人| 国产精品美女久久久久av爽| 99久久免费国产特黄| 久久久国产乱子伦精品作者| 色综合久久综合中文综合网| 亚洲国产精品无码久久98| 国产69精品久久久久9999APGF| 国产A级毛片久久久精品毛片| 久久强奷乱码老熟女网站|