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

            poj3267

            The Cow Lexicon

            Time Limit: 2000MS Memory Limit: 65536K
            Total Submissions: 5619 Accepted: 2599

            Description

            Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their cowmunication system, based on mooing, is not very accurate; sometimes they hear words that do not make any sense. For instance, Bessie once received a message that said "browndcodw". As it turns out, the intended message was "browncow" and the two letter "d"s were noise from other parts of the barnyard.

            The cows want you to help them decipher a received message (also containing only characters in the range 'a'..'z') of length L (2 ≤ L ≤ 300) characters that is a bit garbled. In particular, they know that the message has some extra letters, and they want you to determine the smallest number of letters that must be removed to make the message a sequence of words from the dictionary.

            Input

            Line 1: Two space-separated integers, respectively: W and L
            Line 2: L characters (followed by a newline, of course): the received message
            Lines 3..W+2: The cows' dictionary, one word per line

            Output

            Line 1: a single integer that is the smallest number of characters that need to be removed to make the message a sequence of dictionary words.

            Sample Input

            6 10
            browndcodw
            cow
            milk
            white
            black
            brown
            farmer

            Sample Output

            2
            這個(gè)題目還是跟最長(zhǎng)公共子序列類(lèi)似,
            狀態(tài)表示還是用f[i]表示前i個(gè)中最少去掉的數(shù)目能夠構(gòu)成合法序列
            則f[i]=i
            f[i]=min(f[i],f[j]+remove(s[j+1..i],ss[k]))
            if ss[k]能在s[j+1..i]中表示出來(lái)
            所以我們不必用LCS來(lái)求這個(gè)remove,直接用pp[k]表示第k個(gè)單詞能在s[j+1..i]中匹配到的地方的地方
            如果單詞能在其中表示出來(lái),則min
            這類(lèi)題目的類(lèi)似在于f[i]總是由f[j](0<j<i)推出來(lái)的
             1#include<stdio.h>
             2#include<string.h>
             3#include<math.h>
             4#define MAX 350
             5int f[MAX];
             6char sd[MAX];
             7int pp[610],len[610];
             8char s[610][26];
             9int l1,n,i,j,k;
            10int min(int a,int b)
            11{
            12    if (a>b) return b;
            13    else return a;
            14}

            15int main()
            16{
            17    scanf("%d%d",&n,&l1);
            18    scanf("%s",&sd);
            19    for (i=l1-1;i>=0 ;i-- )
            20    {
            21        sd[i+1]=sd[i];
            22    }

            23    for (i=1; i<=n ; i++ )
            24    {
            25        scanf("%s",&s[i]);
            26        len[i]=strlen(s[i]);
            27    }

            28    for (i=1; i<=l1 ; i++ )
            29    {
            30        f[i]=i;
            31        for (j=1; j<=n ; j++)
            32        {
            33            pp[j]=len[j]-1;
            34        }

            35        for (j=i; j>=1; j--)
            36        {
            37            for (k=1; k<=n ; k++ )
            38            {
            39                if (sd[j]==s[k][pp[k]])
            40                {
            41                    pp[k]--;
            42                }

            43                if (pp[k]<0)
            44                {
            45                    f[i]=min(f[i],f[j-1]+i-j-len[k]+1);
            46                }

            47            }

            48        }

            49    }

            50    printf("%d\n",f[l1]);
            51    return 0;
            52}

            53//f[i]=min(f[j]+remove(s[j+1..i],s[k]))
            54//
            55
             

            posted on 2012-02-21 19:31 jh818012 閱讀(405) 評(píng)論(1)  編輯 收藏 引用

            評(píng)論

            # re: poj3267 2012-02-29 17:23 王私江

            我嚓,我該努力了。  回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄](méi)
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            99久久精品费精品国产| 人妻无码αv中文字幕久久 | 很黄很污的网站久久mimi色| 久久综合五月丁香久久激情| 免费观看成人久久网免费观看| 国产99久久久国产精品小说| 国产成人无码精品久久久久免费| 无码人妻久久一区二区三区免费| 久久久久久无码国产精品中文字幕| 精品熟女少妇av免费久久| av色综合久久天堂av色综合在| 欧美与黑人午夜性猛交久久久| 久久这里只有精品视频99| 亚洲午夜久久久久久久久电影网| 久久夜色精品国产亚洲| 久久人人爽人人爽人人爽 | 久久91精品国产91久| 久久精品视频网| 久久国产视频99电影| 久久精品欧美日韩精品| 99精品久久精品| 大香网伊人久久综合网2020| 日本欧美久久久久免费播放网| 日韩亚洲国产综合久久久| 亚洲综合久久综合激情久久| 久久国产精品无码一区二区三区| 亚洲伊人久久综合影院| 麻豆av久久av盛宴av| 久久久久亚洲精品无码网址| 国产精品久久久久久久久免费| 新狼窝色AV性久久久久久| 亚洲综合久久久| 久久久国产精品网站| 久久精品麻豆日日躁夜夜躁| 欧美亚洲国产精品久久高清| 伊人久久亚洲综合影院| 久久九九兔免费精品6| 久久免费看黄a级毛片| 伊人久久综合无码成人网| 思思久久精品在热线热| 亚洲国产精品无码久久98|