• <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 1171 Letter Game 背包

            思路:

            它的要求是,給你幾個字母,用這些字母拼幾個字典里面有的單詞,所有單詞加起來求最高得分。
            轉化一下,就是個01背包問題。
            由于單詞的長度很短很短了,只有3~7個字母,所以總狀態數很少啦。數組開到 2048 就可以AC了。

            后來又搜了一下別人的解題報告哦,發現有個哥們很牛逼。
            他說:單詞長度范圍在3--7內。所以可能的詞組 只能是 3+3 或 3+4

            一語驚醒腦殘人。太牛逼了!

            代碼 150ms AC。

            #include <stdio.h>

            char key[] = {
                
            "qwertyuiop"
                
            "asdfghjkl"
                
            "zxcvbnm"
            }
            ;
            int score[] = {
                
            7612254135,
                
            214655763,
                
            7746525
            }
            ;

            int map[256], col[256], idx[256], mul[8], tot[8], cnt, hash[2048], top;

            int can_add(int a, int b)
            {
                
            int i, ia, ib;

                
            for (i = 1; i < cnt; i++{
                    ia 
            = (a / mul[i - 1]) % tot[i];
                    ib 
            = (b / mul[i - 1]) % tot[i];
                    
            if (ia + ib >= tot[i])
                        
            return 0;
                }


                
            return 1;
            }


            int main()
            {
                
            int i, val, sum[256], sc;
                
            char str[16];

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

                
            for (i = 0; i < 26; i++)
                    map[key[i]] 
            = score[i];
                
                scanf(
            "%s", str);
                
            for (i = 0; str[i]; i++)
                    col[str[i]]
            ++;

                cnt 
            = 1;
                
            for (i = 'a'; i <= 'z'; i++)
                    
            if (col[i]) {
                        idx[i] 
            = cnt;
                        mul[cnt] 
            = tot[cnt] = col[i] + 1;
                        cnt
            ++;
                    }


                mul[
            0= 1;
                
            for (i = 1; i < cnt; i++)
                    mul[i] 
            *= mul[i - 1];
                top 
            = mul[cnt - 1];
                hash[
            0= 1;

                
            while (scanf("%s", str), str[0!= '.'{
                    
            for (i = 'a'; i <= 'z'; i++)
                        sum[i] 
            = 0;
                    sc 
            = 0;
                    val 
            = 0;
                    
            for (i = 0; str[i]; i++{
                        sum[str[i]]
            ++;
                        
            if (sum[str[i]] > col[str[i]])
                            
            break;
                        sc 
            += map[str[i]];
                        val 
            += mul[idx[str[i]] - 1];
                    }

                    
            if (str[i])
                        
            continue;
                    
            for (i = top; i >= 0; i--{
                        
            if (!hash[i])
                            
            continue;
                        
            if (can_add(i, val) && hash[i + val] < hash[i] + sc)
                            hash[i 
            + val] = hash[i] + sc;
                    }

                }


                sc 
            = 0;
                
            for (i = top; i >= 0; i--)
                    
            if (hash[i] > sc)
                        sc 
            = hash[i];
                printf(
            "%d\n", sc - 1);

                
            return 0;
            }

            posted on 2010-05-10 21:37 糯米 閱讀(505) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            久久SE精品一区二区| 久久青青草原精品国产不卡| 久久久久久国产a免费观看黄色大片 | 国产69精品久久久久99| 久久夜色精品国产亚洲| 久久久久国产亚洲AV麻豆| 亚洲精品国产自在久久| 亚洲精品乱码久久久久66| 久久被窝电影亚洲爽爽爽| 久久国产美女免费观看精品| 99久久香蕉国产线看观香| 久久综合香蕉国产蜜臀AV| 久久亚洲精品中文字幕三区| 日本久久中文字幕| 久久夜色精品国产欧美乱| 国产999精品久久久久久| 久久久久99这里有精品10| 国产国产成人精品久久| 久久九九免费高清视频| 综合网日日天干夜夜久久| 久久精品一区二区| 久久91精品国产91久| 99久久精品日本一区二区免费| 久久久久国产视频电影| 激情伊人五月天久久综合| 污污内射久久一区二区欧美日韩| 无码人妻久久久一区二区三区| 久久亚洲精品视频| 亚洲国产精品无码久久久蜜芽| 2020最新久久久视精品爱| 亚洲一区精品伊人久久伊人| 国产精品国色综合久久| 武侠古典久久婷婷狼人伊人| 亚洲国产二区三区久久| 久久水蜜桃亚洲av无码精品麻豆 | 伊人久久大香线蕉AV色婷婷色| 日韩亚洲欧美久久久www综合网| 欧美亚洲国产精品久久| 久久精品国产只有精品66| 国产一区二区三区久久| 亚洲女久久久噜噜噜熟女|