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

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            老司机午夜网站国内精品久久久久久久久| 久久狠狠一本精品综合网| 久久精品中文无码资源站| 久久91精品久久91综合| 无码任你躁久久久久久久| 色综合久久无码五十路人妻| 亚洲精品国产成人99久久| 香蕉久久久久久狠狠色| 久久精品国产亚洲欧美| 午夜精品久久久内射近拍高清| 少妇高潮惨叫久久久久久| 欧美久久久久久午夜精品| 亚洲AV无码久久精品色欲| 久久久久亚洲精品中文字幕| 久久综合亚洲欧美成人| 亚洲国产成人精品无码久久久久久综合 | 久久久久久亚洲精品不卡 | 亚洲中文字幕无码久久精品1 | 久久天天躁狠狠躁夜夜不卡| 精品九九久久国内精品| 97精品依人久久久大香线蕉97| 99久久亚洲综合精品网站| 日本久久久久亚洲中字幕 | 国产精品一区二区久久精品| 久久中文字幕精品| 久久精品国产只有精品66 | 国产一区二区久久久| 久久91精品综合国产首页| 狠狠色丁香久久婷婷综| 久久偷看各类wc女厕嘘嘘| 欧美黑人激情性久久| 中文字幕精品无码久久久久久3D日动漫| 色综合久久久久| 精品一区二区久久| 国产精品福利一区二区久久| 99久久精品免费看国产一区二区三区 | 伊人久久大香线蕉av不卡 | 亚洲一本综合久久| 久久久久国产一级毛片高清版| 精品久久久久久成人AV| 久久精品国产69国产精品亚洲|