• <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>
            隨筆 - 87  文章 - 279  trackbacks - 0
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            潛心看書(shū)研究!

            常用鏈接

            留言簿(19)

            隨筆分類(lèi)(81)

            文章分類(lèi)(89)

            相冊(cè)

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 216680
            • 排名 - 117

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            Optimal Keypad
            Time Limit:1000MS? Memory Limit:65536K
            Total Submit:168 Accepted:80

            Description
            Optimus Mobiles produces mobile phones that support SMS messages. The Mobiles have a keypad of 12 keys, numbered 1 to 12. There is a character string assigned to each key. To type in the n-th character in the character string of a particular key, one should press the key n times. Optimus Mobiles wishes to solve the problem of assigning character strings to the keys such that for typing a random text out of a dictionary of common words, the average typing effort (i.e. the average number of keystrokes) is minimal.


            Figure 1

            To be more precise, consider a set of characters {a, b, c,..., z, +, *, /, ?} printed on a label tape as in Fig. 2. We want to cut the tape into 12 pieces each containing one or more characters. The 12 labels are numbered 1 to 12 from left to right and will be assigned to the keypad keys in that order.

            Figure 2

            You are to write a program to find the 11 cutting positions for a given dictionary of common words. The cutting positions should minimize the average number of keystrokes over all common words in the dictionary. Your output should be a string of 11 characters, where character i in this string is the first character of the (i+1)th label.

            Input
            The first line contains a single integer t (1 <= t <= 10), the number of test cases. Each test case starts with a line, containing an integer M (1 <= M <= 10000), the number of common words in the test case. In each M subsequent line, there is a common word. Each common word contains at most 30 characters from the alphabet {a, b, c,..., z, +, *, /, ?}.

            Output
            The output contains one line per test case containing an optimal cut string. Obviously, there may be more than a single optimal cut string, so print the optimal cut string which is the smallest one in lexicographic order.

            Sample Input

            2
            2
            hi
            ok
            5
            hello
            bye
            how
            when
            who
            

            Sample Output

            bcdefghijko
            bcdefhlnowy
            

            Source
            Tehran 2003

            #include? < iostream >
            using ? namespace ?std;

            const ? int ?INF? = ? 100000000 ;

            int ?f[ 13 ][ 30 ][ 30 ];
            int ?s[ 13 ][ 30 ][ 30 ];
            int ?l[ 13 ][ 30 ][ 30 ];
            char ?c[]? = ? { ' a ' ,? ' b ' ,? ' c ' ,? ' d ' ,? ' e ' ,? ' f ' ,? ' g ' ,? ' h ' ,? ' i ' ,? ' j ' ,? ' k ' ,? ' l ' ,? ' m ' ,? ' n ' ,? ' o '
            ????????????,?
            ' p ' ,? ' q ' ,? ' r ' ,? ' s ' ,? ' t ' ,? ' u ' ,? ' v ' ,? ' w ' ,? ' x ' ,? ' y ' ,? ' z ' ,? ' + ' ,? ' * ' ,? ' / ' ,? ' ? ' }
            ;

            void ?OutPut( int ?k,? int ?i,? int ?j)
            {
            ????
            if ?(l[k][i][j]? >= ? 0 )
            ????
            {
            ????????OutPut(l[k][i][j],?i,?s[k][i][j]);
            ????
            ????????printf(
            " %c " ,?c[s[k][i][j] + 1 ]);
            ????????
            ????????OutPut(k
            - l[k][i][j],?s[k][i][j] + 1 ,?j);????
            ????}

            }


            void ?Solve()
            {
            ????
            int ?n;
            ????
            int ?i,?j,?k,?p,?q,?t,?e;
            ????
            int ?cntLable[ 300 ]? = ? { 0 } ;
            ????
            int ?sum;
            ????
            char ?tmpS[ 31 ];
            ????scanf(
            " %d " ,? & n);
            ????
            for ?(i = 0 ;?i < n;?i ++ )
            ????
            {
            ????????scanf(
            " %s " ,?tmpS);
            ????????
            for ?(j = 0 ;?j < strlen(tmpS);?j ++ )
            ????????????cntLable[tmpS[j]]
            ++ ;
            ????}


            ????
            for ?(k = 1 ;?k <= 12 ;?k ++ )
            ????????
            for ?(i = 0 ;?i < 30 ;?i ++ )
            ????????????
            for ?(j = 0 ;?j < 30 ;?j ++ )
            ????????????
            {
            ????????????????f[k][i][j]?
            = ?INF;
            ????????????????s[k][i][j]?
            = ? - 1 ;
            ????????????????l[k][i][j]?
            = ? - 1 ;
            ????????????}


            ????
            // init?k=1
            ???? for ?(i = 0 ;?i < 30 ;?i ++ )
            ????
            {
            ????????sum?
            = ? 0 ;
            ????????
            for ?(j = i,?k = 1 ;?j < 30 ;?j ++ ,?k ++ )
            ????????
            {
            ????????????sum?
            += ?cntLable[c[j]]? * ?k;
            ????????????f[
            1 ][i][j]? = ?sum;
            ????????}

            ????}


            ????
            for ?(k = 2 ;?k <= 12 ;?k ++ )
            ????????
            for ?(i = 0 ;?i < 30 ;?i ++ )
            ????????????
            for ?(j = i + k - 1 ;?j < 30 ;?j ++ )
            ????????????
            {
            ????????????????
            for ?(t = i;?t < j;?t ++ )
            ????????????????
            {
            ????????????????????e?
            = ?k - 1 ? < ?t - i + 1 ? ? ?k - 1 ?:?t - i + 1 ;
            ????????????????????
            for ?(p = 1 ;?p <= e;?p ++ )
            ????????????????????????
            if ?(f[k][i][j]? > ?f[p][i][t]? + ?f[k - p][t + 1 ][j])
            ????????????????????????
            {
            ????????????????????????????f[k][i][j]?
            = ?f[p][i][t]? + ?f[k - p][t + 1 ][j];
            ????????????????????????????s[k][i][j]?
            = ?t;
            ????????????????????????????l[k][i][j]?
            = ?p;
            ????????????????????????}

            ????????????????}

            ????????????}


            ????OutPut(
            12 ,? 0 ,? 29 );
            ????printf(
            " \n " );
            }


            int ?main()
            {
            ????
            int ?n;
            ????scanf(
            " %d " ,? & n);
            ????
            while ?(n -- ? != ? 0 )
            ????
            {
            ????????Solve();
            ????}

            ????
            return ? 0 ;
            }
            posted on 2006-09-26 18:51 閱讀(512) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): ACM題目

            FeedBack:
            # re: 線形模型中分, 三維DP(pku2292) 2006-10-05 01:15 Asp
            這道題我也做了,但是似乎理解錯(cuò)了題意,結(jié)果,WA了2個(gè)小時(shí)……
            之后,放棄……  回復(fù)  更多評(píng)論
              
            亚洲国产日韩欧美久久| 综合网日日天干夜夜久久 | 久久婷婷五月综合色高清| 精品人妻伦一二三区久久| 国产精品久久久福利| 久久婷婷五月综合色高清 | 亚洲精品国精品久久99热一| 亚洲欧洲中文日韩久久AV乱码| 国产一区二区精品久久凹凸 | 久久精品中文字幕有码| 久久97精品久久久久久久不卡| 精品国产乱码久久久久久郑州公司| 久久人做人爽一区二区三区| 久久精品免费全国观看国产| 久久久久亚洲av成人网人人软件| 亚洲七七久久精品中文国产| 亚洲精品NV久久久久久久久久| 亚洲精品无码久久久久AV麻豆| 欧美日韩成人精品久久久免费看 | 久久久久亚洲精品日久生情| 久久久精品国产免大香伊| 亚洲精品白浆高清久久久久久| 久久久久se色偷偷亚洲精品av| 亚洲国产精品久久电影欧美| 看久久久久久a级毛片| 国产婷婷成人久久Av免费高清| 久久久中文字幕| 色8激情欧美成人久久综合电| 人妻无码αv中文字幕久久琪琪布| 国产A三级久久精品| 精品熟女少妇av免费久久| 国产激情久久久久影院老熟女| 欧美伊人久久大香线蕉综合69 | 欧美噜噜久久久XXX| 秋霞久久国产精品电影院| 人人狠狠综合久久亚洲高清| 久久亚洲精品无码VA大香大香| 91精品国产91久久久久福利| 久久久久国产精品三级网| 久久综合噜噜激激的五月天| 青青青青久久精品国产|