Created
February 25, 2013 00:10
-
-
Save rve/5026374 to your computer and use it in GitHub Desktop.
kimbits half
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<cstdio> | |
#include<cstring> | |
#include<algorithm> | |
#include<string> | |
#define MAXN 33 | |
#define INF 0x3f3f3f3f | |
using namespace std; | |
int size[MAXN][MAXN]; | |
string ans; | |
int n, l, nth; | |
void printbits(int n, int l, int nth); | |
int main() | |
{ | |
memset(size, 0, sizeof(size)); | |
size[1][1] = 1; | |
scanf("%d %d %d", &n, &l, &nth); | |
for(int i=1; i<=n; i++) | |
size[i][0] = 1, size[i][i] = 1; | |
for(int i=2; i<=n; i++) | |
for(int j=1; j<i; j++) | |
size[i][j] = size[i-1][j] + size[i-1][j-1]; | |
for(int i=1; i<=n; i++) | |
for(int j=1; j<=i; j++) | |
size[i][j] += size[i][j-1]; | |
printbits(n, l, nth); | |
cout<<ans<<endl; | |
} | |
void printbits(int n, int l, int nth) | |
{ | |
if (nth == 1) { ans += '0'; return;} | |
if (nth == 2) { ans += '1'; return;} | |
if (size[n - 1][l] >= nth ) | |
{ | |
ans += '0'; | |
printbits(n-1, l, nth); | |
} | |
else | |
{ | |
ans += '1'; | |
printbits(n-1, l-1, nth - size[n-1][l]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment