• <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 Section 3.2 Stringsobits

            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
            Analysis

            At first glance of it, it is nice for a single integer saving situations rather than string which is told in the description. But for the 10th data, it seems small for 31 31 2^31. To deal with it, take it away and print answer independently. For other situations, find the maximum bit recursively.

            Code

            /*
            ID:braytay1
            PROG:kimbits
            LANG:C++
            */

            #include 
            <iostream>
            #include 
            <fstream>
            using namespace std;
            int cmb_lab[34][34];
            int cmb_num[34][34];
            int n,l;
            long long int no;
            int count(long long int s){
                
            int ret=0;
                
            while (s){
                    s
            &=(s-1);
                    ret
            ++;
                }

                
            return ret;
            }

            long long int dealing(long long int a,int l1){
                
            if (a<=1return 0;
                
            int cur;
                
            long int cur_sum=0;
                
            for (cur=0;cur<=n;cur++){
                    cur_sum
            +=cmb_num[cur][l1 ];
                    
            if (cur_sum>=a) break;
                }

                
            long long int leave;
                
            long long int res;
                leave
            =a-cur_sum+cmb_num[cur][l1];
                res
            =1<<(cur-1);
                res
            +=dealing(leave,l1-1);
                
            return res;
            }

            int main(){
                ifstream fin(
            "kimbits.in");
                ofstream fout(
            "kimbits.out");
                fin
            >>n>>l>>no;
                
            if (no==1){
                    
            for (int i=1;i<=n;i++)
                        fout
            <<0;
                    fout
            <<endl;
                    
            return 0;
                }

                memset(cmb_lab,
            0,sizeof(cmb_lab));
                cmb_lab[
            0][0]=1;
                
            for (int i=1;i<=32;i++){
                    
            for (int j=0;j<=32;j++){
                        
            if (j==0||j==i) cmb_lab[i][j]=1;
                        
            else cmb_lab[i][j]=cmb_lab[i-1][j-1]+cmb_lab[i-1][j];
                    }

                }

                
            for (int k=0;k<=l;k++){
                    
            if (k>0) cmb_num[0][k]=1;
                    
            else cmb_num[0][k]=0;
                    
            for (int i=1;i<=n;i++){
                        
            int sum=0;
                        
            for (int j=0;j<k;j++){
                            sum
            +=cmb_lab[i-1][j];
                        }

                        cmb_num[i][k]
            =sum;
                    }

                }

                
            long long int res;
                
            if (n==31&&l==31{
                    res
            =no-1;
                    
            for (int i=n-1;i>=0;i--){
                        
            if (res&(1<<i)) fout<<1;
                        
            else fout<<0;
                    }

                    fout
            <<endl;
                    
            return 0;
                }

                res
            =dealing(no,l);
                
            for (int i=n-1;i>=0;i--){
                    
            if (res&(1<<i)) fout<<1;
                    
            else fout<<0;
                }

                fout
            <<endl;
                
            return 0;
            }

            posted on 2008-08-27 17:20 幻浪天空領主 閱讀(343) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久er国产精品免费观看2| 亚洲伊人久久综合影院| 国产亚洲精品美女久久久| 国产91久久精品一区二区| 久久国产综合精品五月天| 亚洲精品综合久久| 久久99国产精一区二区三区| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 99久久免费国产特黄| 国产精品99久久久久久董美香 | 丰满少妇人妻久久久久久| 国产福利电影一区二区三区,免费久久久久久久精 | 精品久久香蕉国产线看观看亚洲| 激情久久久久久久久久| 丁香色欲久久久久久综合网| 国产91色综合久久免费| 久久人人爽人人爽人人片AV不| 精品午夜久久福利大片| 久久这里只有精品首页| 久久国产免费直播| 亚洲综合精品香蕉久久网97| 亚洲精品乱码久久久久久| 久久久这里有精品中文字幕| 亚洲一本综合久久| 91久久精品无码一区二区毛片| 久久亚洲AV成人无码软件| 香港aa三级久久三级老师2021国产三级精品三级在| 人人狠狠综合久久88成人| 久久大香萑太香蕉av| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 日韩精品久久久肉伦网站 | 国产精品久久久久久影院| 国产69精品久久久久久人妻精品| 性做久久久久久久久老女人| 久久久久久A亚洲欧洲AV冫| 久久成人18免费网站| 国产综合精品久久亚洲| 国产高潮久久免费观看| 久久九九免费高清视频| 久久精品综合一区二区三区| 日韩十八禁一区二区久久 |