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

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            青青草原1769久久免费播放| 中文字幕无码免费久久| 亚洲乱亚洲乱淫久久| 亚洲欧美一级久久精品| 久久久精品人妻一区二区三区四| 国产精品99久久99久久久| 国産精品久久久久久久| 亚洲日韩中文无码久久| 2020最新久久久视精品爱| 国产精品久久婷婷六月丁香| 色综合久久中文色婷婷| 亚洲精品99久久久久中文字幕| 久久久久99精品成人片直播| 久久夜色精品国产噜噜亚洲a| 国产精品99久久免费观看| 久久99这里只有精品国产| 热99re久久国超精品首页| 蜜臀av性久久久久蜜臀aⅴ| 久久免费香蕉视频| 国产成人久久777777| 久久99国产精品久久久 | 久久精品无码一区二区三区免费 | 久久免费国产精品一区二区| 国内精品久久久久影院亚洲| 久久精品免费网站网| 999久久久国产精品| 久久久久国产一级毛片高清版| 久久精品国产免费观看| 性做久久久久久久久浪潮| 亚洲精品国产综合久久一线| 久久精品视屏| 奇米影视7777久久精品人人爽| 香蕉99久久国产综合精品宅男自| 国产激情久久久久影院老熟女免费| 国产V亚洲V天堂无码久久久| 99久久精品国产高清一区二区| 波多野结衣中文字幕久久| 久久香蕉国产线看观看精品yw| 久久精品中文无码资源站| 久久99精品久久久久久| www亚洲欲色成人久久精品|