• <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
            国产午夜精品理论片久久影视| 久久久久亚洲爆乳少妇无| 久久亚洲国产最新网站| 久久久久亚洲国产| 久久精品国产亚洲AV无码娇色 | 国产一区二区久久久| 色偷偷偷久久伊人大杳蕉| 国产精品久久久99| 午夜人妻久久久久久久久| www亚洲欲色成人久久精品| 久久精品人妻中文系列| 久久99精品综合国产首页| 久久受www免费人成_看片中文| 99久久综合狠狠综合久久止| 亚洲国产精品综合久久网络| 大伊人青草狠狠久久| 久久人人爽人人爽人人片AV不| 久久最新精品国产| 久久久久人妻一区精品色| 香蕉久久影院| 精品久久久久久久久久中文字幕 | av午夜福利一片免费看久久| 久久WWW免费人成—看片| 九九精品99久久久香蕉| 久久天天躁夜夜躁狠狠躁2022| 99久久成人18免费网站| 久久婷婷综合中文字幕| 久久99国产综合精品女同| 综合网日日天干夜夜久久 | 久久w5ww成w人免费| 97久久婷婷五月综合色d啪蜜芽| 久久亚洲中文字幕精品一区四| 国产精品嫩草影院久久| 久久99精品久久久久久野外| 伊人色综合久久| 狠狠色综合网站久久久久久久| 狠狠色丁香久久综合婷婷| 狠狠色丁香婷婷综合久久来 | 久久这里只有精品首页| 武侠古典久久婷婷狼人伊人| 久久男人中文字幕资源站|