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

            USACO 3.2 Stringsobits


            首先計(jì)算出組合數(shù)。用cmb_num[i][j]表示i位數(shù)中,"1的位數(shù)小于等于j"的數(shù)的個(gè)數(shù)。
            這樣,我們從最左邊開始,如果cmb_num[i-1][j]的數(shù)大于n,說明第一位為0,因?yàn)橛胕-1位數(shù)中"1的位數(shù)小于等于j"的數(shù)已經(jīng)大于n個(gè)了。
            如果小于n,說明第一位為1,需要i位,才能使"1的位數(shù)小于等于j"的數(shù)大于n個(gè)了。既然第一位已經(jīng)是1了,接下來的i-1位組成的數(shù)的1的個(gè)數(shù)只能小于等于n-1位了。迭代輸出每一位即可。
            只是要注意溢出的問題以及cmb_num[0][1]。

            #include?<iostream>
            #include?
            <fstream>

            using?namespace?std;

            ifstream?fin(
            "kimbits.in");
            ofstream?fout(
            "kimbits.out");

            #ifdef?_DEBUG
            #define?out?cout
            #define?in?cin
            #else
            #define?out?fout
            #define?in?fin
            #endif

            unsigned?
            int?cmb_num[32][32];

            void?build_cmb_num()
            {
            ????
            for(int?i=0;i<32;++i)
            ????????cmb_num[i][
            0]?=?1;

            ????
            for(int?i=1;i<32;++i)
            ????????
            for(int?j=1;j<=i;++j)
            ????????????cmb_num[i][j]?
            =?cmb_num[i-1][j-1]+cmb_num[i-1][j];

            ????
            for(int?i=0;i<32;++i)
            ????????
            for(int?j=1;j<32;++j){
            ????????????cmb_num[i][j]
            +=cmb_num[i][j-1];
            ????????}
            }


            void?solve()
            {
            ????build_cmb_num();

            ????unsigned??n,l,i;
            ????
            in>>n>>l>>i;

            ????
            for(unsigned?idx=n;idx>0;--idx){
            ????????
            if(?i>?cmb_num[idx-1][l]?){
            ????????????
            out<<1;
            ????????????i
            -=cmb_num[idx-1][l];
            ????????????l
            --;
            ????????}
            else{
            ????????????
            out<<0;
            ????????}???
            ????}

            ????
            out<<endl;
            }

            int?main(int?argc,char?*argv[])
            {
            ????solve();?
            ????
            return?0;
            }

            附題:
            Stringsobits
            Kim Schrijvers

            Consider an ordered set S of strings of N (1 <= N <= 31) bits. Bits, of course, are either 0 or 1.

            This set of strings is interesting because it is ordered and contains all possible strings of length N that have L (1 <= L <= N) or fewer bits that are `1'.

            Your task is to read a number I (1 <= I <= sizeof(S)) from the input and print the Ith element of the ordered set for N bits with no more than L bits that are `1'.

            PROGRAM NAME: kimbits

            INPUT FORMAT

            A single line with three space separated integers: N, L, and I.

            SAMPLE INPUT (file kimbits.in)

            5 3 19

            OUTPUT FORMAT

            A single line containing the integer that represents the Ith element from the order set, as described.

            SAMPLE OUTPUT (file kimbits.out)

            10011

            posted on 2009-07-03 20:45 YZY 閱讀(535) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Algorithm 、USACO

            導(dǎo)航

            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            統(tǒng)計(jì)

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            久久久精品人妻一区二区三区四| 精品久久久久久国产91| 久久久久久国产精品免费免费 | 久久九九兔免费精品6| 久久久久久曰本AV免费免费| 欧美一区二区三区久久综合| 免费国产99久久久香蕉| 青青草国产97免久久费观看| 无码国内精品久久人妻蜜桃| 成人国内精品久久久久影院VR| 久久这里有精品视频| 国产婷婷成人久久Av免费高清| 久久久久久久久久免免费精品| 午夜精品久久久久久久| 久久精品国产一区二区 | 91精品无码久久久久久五月天| 污污内射久久一区二区欧美日韩| 久久精品中文无码资源站| 亚洲国产精品综合久久一线| 久久99精品国产麻豆宅宅| 久久精品国产精品亚洲精品| 97精品国产97久久久久久免费| 亚洲αv久久久噜噜噜噜噜| 久久天天躁狠狠躁夜夜不卡| 久久91亚洲人成电影网站| 日韩欧美亚洲综合久久| 欧美日韩精品久久久久| 国产精品九九久久精品女同亚洲欧美日韩综合区| 一本色道久久88综合日韩精品| 久久精品国产亚洲av瑜伽| 91麻豆精品国产91久久久久久| 久久精品国产亚洲欧美| 久久久精品人妻一区二区三区蜜桃 | 久久天天躁狠狠躁夜夜avapp| 人妻系列无码专区久久五月天| 青青草原1769久久免费播放| 国产精品久久成人影院| 国产精品久久亚洲不卡动漫| 精品久久人妻av中文字幕| 久久99国内精品自在现线| 国产精品欧美久久久天天影视|