-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2248.cpp
More file actions
43 lines (38 loc) · 869 Bytes
/
2248.cpp
File metadata and controls
43 lines (38 loc) · 869 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int dp[32][32];
char result[32];
int binary(int n, int m) {
int &ret = dp[n][m];
if (ret != -1) return ret;
if (n == 0 || m == 0) return ret = 1;
ret = binary(n - 1, m);
if (m > 0) ret += binary(n - 1, m - 1);
return ret;
}
void skip(int n, int m, int k, int p) {
if (n == 0) return;
if (m == 0) {
for (int i = 0; i < n; i++)
result[p + i] = '0';
return;
}
int pivot = binary(n - 1, m);
if (k < pivot) {
result[p] = '0';
skip(n - 1, m, k, p + 1);
} else {
result[p] = '1';
skip(n - 1, m - 1, k - pivot, p + 1);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, L;
long long I;
cin >> N >> L >> I;
memset(dp, -1, sizeof(dp));
skip(N, L, I-1, 0);
cout << result;
}