[Usaco3.2.2]kimbits

Source: Internet
Author: User

The problem is also a question of reading.

Thought is that: we enumerate to the I digit has J 1, uses the Yang Hui triangle to seek the combination number, the first row J column is C (i-1,j-1), uses the sum[i][j] to represent I the number 0. J 1 of all the numbers of the number, then Sum[i][j]=c (i,0) +c (i,1) +......+c (i,j), then when we ask for the number of K, when Sum[i-1][j] (i-1, 0...J 1 scheme number) <k, it means that the first bit is 1 , otherwise it is 0, and so on.

/*id:abc31261lang:c++task:kimbits*/#include<cstdio>#include<cstring>#include<iostream>using namespacestd;Const intmaxn= -;Long Longsum,f[maxn][maxn],n,k,l;intMain () {inti,j; Freopen ("kimbits.in","R", stdin); Freopen ("Kimbits.out","W", stdout); CIN>>n>>l>>K; f[0][0]=1;  for(i=1; i<=n;i++)         for(j=1; j<=n;j++) f[i][j]=f[i-1][j-1]+f[i-1][J];//Yang Hui Triangle     for(i=n;i>=1; i--)    {        if(l==0) printf ("0"); Else{sum=0;  for(j=1; j<=l+1; j + +) Sum+=f[i][j];//Yang Hui triangle starting from 1, the first row i, Column J, is C (i-1,j-1);            if(sum>=k) printf ("0"); Else{printf ("1"); K-=sum;//subtract the number of scenarios where I bit is 0l--; } }} cout<<Endl; return 0;}

[Usaco3.2.2]kimbits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.