• <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 閱讀(299) 評論(0)  編輯 收藏 引用
            精品久久久久国产免费| 69久久精品无码一区二区| 久久精品国产久精国产思思| 亚洲欧美精品一区久久中文字幕| 99久久精品国产一区二区| 97精品伊人久久久大香线蕉| 久久精品国产亚洲麻豆| 精品一区二区久久| 国产精品成人久久久久久久| 国产精品亚洲综合专区片高清久久久| 99久久精品免费看国产| 久久嫩草影院免费看夜色| 欧美一级久久久久久久大| 久久伊人精品一区二区三区| 97精品伊人久久久大香线蕉| 亚洲va久久久噜噜噜久久天堂| 精品久久久无码人妻中文字幕豆芽| 久久精品无码一区二区无码 | 久久久久久九九99精品| 久久久久久久久无码精品亚洲日韩| 精品蜜臀久久久久99网站| 久久精品无码一区二区三区| 久久久久婷婷| 久久久无码人妻精品无码| 91精品国产91久久久久久青草| 天天影视色香欲综合久久| 久久国产亚洲精品无码| 国产激情久久久久影院老熟女| 亚洲国产小视频精品久久久三级| 日产精品久久久久久久| 久久久久亚洲AV无码专区桃色| 国内精品久久久久影院薰衣草| 久久r热这里有精品视频| 色综合久久久久综合99| 精品久久8x国产免费观看| 久久久久亚洲精品男人的天堂| 亚洲伊人久久精品影院| 久久精品国产72国产精福利| 亚洲国产欧美国产综合久久| 久久久精品国产亚洲成人满18免费网站 | 91久久香蕉国产熟女线看|