• <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 幻浪天空領主 閱讀(344) 評論(0)  編輯 收藏 引用 所屬分類: USACO

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

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久国产亚洲精品| 午夜欧美精品久久久久久久| 精品国产91久久久久久久| 久久精品国产91久久综合麻豆自制 | 一级A毛片免费观看久久精品| 天天综合久久一二三区| 99久久99久久精品国产片果冻| 国产成人精品白浆久久69 | 久久99亚洲综合精品首页| 久久这里的只有是精品23| av午夜福利一片免费看久久| 久久久久亚洲精品无码网址| 日韩人妻无码一区二区三区久久 | 久久久一本精品99久久精品88| 久久综合九色综合精品| 99久久国产宗和精品1上映| 久久精品成人一区二区三区| 久久这里只有精品18| 污污内射久久一区二区欧美日韩 | 一本大道久久a久久精品综合| 精品国产日韩久久亚洲| 国产日韩久久免费影院| 久久九九精品99国产精品| 老男人久久青草av高清| 免费一级欧美大片久久网| 9久久9久久精品| 亚洲AV无码久久| 97久久国产综合精品女不卡 | 亚洲AV日韩精品久久久久久| 久久亚洲天堂| 天天影视色香欲综合久久| 国产高清美女一级a毛片久久w | 久久AV高清无码| 久久精品国产亚洲αv忘忧草| 久久伊人五月天论坛| 久久婷婷色综合一区二区| 久久精品国产黑森林| 久久久亚洲精品蜜桃臀| 久久无码一区二区三区少妇| 国产精品va久久久久久久| 精品久久久久久无码中文字幕 |