• <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 閱讀(109) 評論(0)  編輯 收藏 引用 所屬分類: DP

            <2011年1月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            欧美亚洲另类久久综合婷婷| 久久久久久久波多野结衣高潮| 999久久久无码国产精品| 97久久精品人妻人人搡人人玩| 久久最近最新中文字幕大全| 久久青青国产| 国产精品一区二区久久不卡| 欧美一级久久久久久久大| 国内精品伊人久久久久AV影院| 久久www免费人成精品香蕉| 无码人妻久久一区二区三区| 久久精品国产精品亜洲毛片| 亚洲国产精品无码久久98| 久久综合日本熟妇| 热99re久久国超精品首页| 国产成年无码久久久免费| 久久无码AV中文出轨人妻| 国产精品久久永久免费| 99久久精品国产一区二区 | 精品人妻伦九区久久AAA片69| A级毛片无码久久精品免费| 国产精品无码久久久久久| 亚洲欧美另类日本久久国产真实乱对白 | 久久香蕉国产线看观看乱码| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 伊人久久大香线蕉av不卡| 久久综合一区二区无码| 国内精品久久久久久不卡影院| 91精品国产91久久久久福利| 久久久无码精品亚洲日韩按摩| 99久久精品国产一区二区 | 亚洲精品美女久久久久99| 亚洲国产成人久久综合碰| 亚洲v国产v天堂a无码久久| 久久影视综合亚洲| 亚洲国产精品成人久久蜜臀| 日本久久久久久久久久| 漂亮人妻被中出中文字幕久久| 麻豆久久久9性大片| 久久久久久国产精品无码下载| 亚洲狠狠婷婷综合久久蜜芽|