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

            pku1850 code 求字符串的位置,DP

            給出一個字符串的序
            The coding system works like this:
            • The words are arranged in the increasing order of their length.
            • The words with the same length are arranged in lexicographical order (the order from the dictionary).
            • We codify these words by their numbering, starting with a, as follows:
            a - 1
            b - 2
            ...
            z - 26
            ab - 27
            ...
            az - 51
            bc - 52
            ...
            vwxyz - 83681
            ...
            然后給出一個字符串,要求求在字典中的位置。
            設狀態dp[l][p]為長度為l的字符串且以p為字母開頭的個數為多少。
            dp[l][p]=sum{dp[l-1][i]} i>k
            下面就不用解釋了吧- -

             1# include <cstdio>
             2# include <iostream>
             3# include <cstring>
             4using namespace std;
             5int dp[11][26];
             6int main()
             7{
             8    memset(dp,0,sizeof(dp));
             9    for(int i=0;i<26;i++)
            10      dp[1][i]=1;
            11    for(int len=2;len<=10;len++)
            12        for(int i=0;i<26;i++)
            13          for(int j=i+1;j<26;j++)
            14            dp[len][i]+=dp[len-1][j];
            15   char str[100];
            16   scanf("%s",str);
            17   for(int i=1;i<strlen(str);i++)
            18     if(str[i]<=str[i-1])
            19     {
            20        printf("0\n");
            21        return 0;
            22     }

            23   int total=0;
            24   for(int len=0;len<strlen(str);len++)
            25     for(int i=0;i<26;i++)
            26       total+=dp[len][i];
            27   int last=0;
            28   for(int i=0;i<strlen(str);i++)
            29   {
            30     for(int j=last;j<str[i]-'a';j++)
            31       total+=dp[strlen(str)-i][j];
            32     last=str[i]-'a'+1;
            33   }

            34   printf("%d\n",total+1);
            35   //system("pause");
            36   return 0;
            37    
            38}

            39

            posted on 2010-10-28 00:58 yzhw 閱讀(104) 評論(0)  編輯 收藏 引用 所屬分類: DP

            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            国产91久久综合| 国产欧美久久久精品影院| 久久99精品久久久久久久不卡| 日韩中文久久| 亚洲中文字幕无码久久综合网| 久久久久久久久久久久中文字幕 | 91精品免费久久久久久久久| 久久天天躁狠狠躁夜夜av浪潮 | 亚洲精品NV久久久久久久久久| 国产aⅴ激情无码久久| 狠狠干狠狠久久| 精品久久久无码人妻中文字幕| 99久久99久久久精品齐齐| 久久久精品国产亚洲成人满18免费网站| 久久久免费观成人影院| 精品少妇人妻av无码久久| 久久亚洲国产成人影院网站| 精品久久久久久国产潘金莲| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 久久99精品国产麻豆| 亚洲成av人片不卡无码久久| 青青草原1769久久免费播放| 午夜精品久久久久久中宇| 亚洲欧洲精品成人久久曰影片| 日本精品久久久中文字幕| 亚洲va中文字幕无码久久| 无码任你躁久久久久久久| 久久久久久亚洲精品无码| 99re这里只有精品热久久| 亚洲欧洲日产国码无码久久99| 色婷婷久久综合中文久久一本| 久久99精品九九九久久婷婷| 久久久青草久久久青草| 72种姿势欧美久久久久大黄蕉| 无码国内精品久久人妻| 色综合久久夜色精品国产| 老司机午夜网站国内精品久久久久久久久| 久久久久99精品成人片试看| 一本色道久久综合狠狠躁 | 久久婷婷五月综合97色| 欧美午夜精品久久久久免费视|