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

            糯米

            TI DaVinci, gstreamer, ffmpeg
            隨筆 - 167, 文章 - 0, 評論 - 47, 引用 - 0
            數據加載中……

            POJ 3188 Cellphones 枚舉+hash

            思路:

            這題是暴力枚舉,哈哈。
            枚舉每一種可能的字母分配情況。
            然后再對每個單詞求出按鍵序列以后,對按鍵序列進行 hash,用普通的字串hash函數即可。
            最后就可以統計具有唯一按鍵序列的單詞個數了。

            這種做法還是相當快的,代碼跑到了450ms 。是第一哦!

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

            #define MAX_D 1024
            #define HASH_SIZE 65536

            struct node {
                
            struct node *next;
                
            int val, cnt;
            }
            ;

            int B, L, D;
            int map[256], ans[256], best;
            char dict[MAX_D][16];
            struct node nodes[MAX_D], *hash[HASH_SIZE];
            int nodes_cnt;
            int vis[HASH_SIZE], tm;

            inline 
            void calc()
            {
                
            int i, h, val, uni;
                
            char *s;
                
            struct node *t;

                tm
            ++;
                nodes_cnt 
            = 0;
                
            for (i = 0; i < D; i++{
                    val 
            = 0;
                    
            for (s = dict[i]; *s; s++
                        val 
            = val*31 + map[*s] + 'a';
                    h 
            = val & (HASH_SIZE - 1);
                    
            if (vis[h] != tm) {
                        vis[h] 
            = tm;
                        hash[h] 
            = NULL;
                    }

                    
            for (t = hash[h]; t; t = t->next)
                        
            if (t->val == val)
                            
            break;
                    
            if (!t) {
                        t 
            = &nodes[nodes_cnt++];
                        t
            ->val = val;
                        t
            ->cnt = 0;
                        t
            ->next = hash[h];
                        hash[h] 
            = t;
                    }

                    t
            ->cnt++;
                }


                uni 
            = 0;
                
            for (i = 0; i < nodes_cnt; i++)
                    
            if (nodes[i].cnt == 1)
                        uni
            ++;

                
            if (uni > best) {
                    best 
            = uni;
                    memcpy(ans, map, 
            sizeof(map));
                }

            }


            void dfs(int b, int l)
            {
                
            int i, cnt;

                cnt 
            = L - l - (B - b) + 1;
                
            for (i = 0; i < cnt; i++)
                    map[l 
            + 'A' + i] = b;
                
                
            if (b == B - 1{
                    calc();
                    
            return ;
                }


                
            for (i = cnt; i >= 1; i--)
                    dfs(b 
            + 1, l + i);
            }


            int main()
            {
                
            int i;

                freopen(
            "e:\\test\\in.txt""r", stdin);

                scanf(
            "%d%d%d"&B, &L, &D);
                
            for (i = 0; i < D; i++)
                    scanf(
            "%s", dict[i]);
                dfs(
            00);
                printf(
            "%d\n", best);
                
            for (i = 'A'; i < 'A' + L; i++{
                    
            if (ans[i] != ans[i - 1])
                        putchar(
            '\n');
                    putchar(i);
                }

                putchar(
            '\n');

                
            return 0;
            }

            posted on 2010-04-26 19:28 糯米 閱讀(628) 評論(1)  編輯 收藏 引用 所屬分類: POJ

            評論

            # re: POJ 3188 Cellphones 枚舉+hash  回復  更多評論   

            稍加優化即可刷到344Ms,我現在是第一了,呵呵。
            2011-07-06 18:19 | fanhqme
            噜噜噜色噜噜噜久久| 国产A级毛片久久久精品毛片| 亚洲女久久久噜噜噜熟女| 欧美亚洲色综久久精品国产| 久久成人精品视频| 亚洲性久久久影院| 国产精品一久久香蕉国产线看观看| 久久综合狠狠综合久久激情 | 中文字幕无码免费久久| 亚洲狠狠婷婷综合久久蜜芽| 91麻精品国产91久久久久| 色8激情欧美成人久久综合电| 亚洲国产精品成人久久| 亚洲嫩草影院久久精品| 久久丫精品国产亚洲av| 久久夜色精品国产| 天天爽天天爽天天片a久久网| 久久精品九九亚洲精品| 日本WV一本一道久久香蕉| 很黄很污的网站久久mimi色| 国产国产成人精品久久| 99久久99久久| 精品久久久中文字幕人妻| 久久精品国产亚洲AV不卡| 美女写真久久影院| 久久久久久久久无码精品亚洲日韩 | 久久久精品国产sm调教网站| 亚洲精品乱码久久久久久蜜桃| 国产精品天天影视久久综合网| 色综合久久久久综合体桃花网| 伊人久久大香线蕉精品不卡| 久久se这里只有精品| 久久www免费人成看国产片| 久久国产一区二区| 成人妇女免费播放久久久| 久久亚洲精品中文字幕| 日本欧美久久久久免费播放网| 亚洲精品无码久久久影院相关影片 | 久久丝袜精品中文字幕| 狠狠色伊人久久精品综合网| 99久久国产综合精品网成人影院 |