USACO Stringsobits

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
ID: wcr19961
PROG: kimbits
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 35;
LL c[maxn][maxn];

int main() {
freopen("kimbits.in", "r", stdin);
freopen("kimbits.out", "w", stdout);
for (int i = 0; i < maxn; ++i) {
c[i][0] = 1;
for (int j = 1; j <= i; ++j) {
c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
}
for (int i = 0; i < maxn; ++i) {
for (int j = 1; j < maxn; ++j) {
c[i][j] += c[i][j - 1];
}
}
int n, l;
LL x;
scanf("%d%d%lld", &n, &l, &x);
for (int i = 0; i < n; ++i) {
if (x > c[n - i - 1][l]) {
x -= c[n - i - 1][l];
--l;
putchar('1');
} else {
putchar('0');
}
}
puts("");
return 0;
}