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