-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkimbits.java
More file actions
55 lines (48 loc) · 1.23 KB
/
Copy pathkimbits.java
File metadata and controls
55 lines (48 loc) · 1.23 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
/*
ID: 001207j1
LANG: JAVA
TASK: kimbits
*/
import java.io.*;
public class kimbits {
public static int N, L;
public static long I;
public static int[][] dp;
public static void main(String[] args) throws Exception {
kimbits k = new kimbits();
k.run();
}
public static void run() throws Exception {
BufferedReader f = new BufferedReader(new FileReader("kimbits.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("kimbits.out")));
String s[] = f.readLine().split(" ");
N = Integer.parseInt(s[0]);
L = Integer.parseInt(s[1]);
I = Long.parseLong(s[2]);
dp = new int[N + 1][L + 1];
for (int i = 0; i <= L; i++)
dp[0][i] = 1;
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= L; j++)
if (j == 0)
dp[i][j] = 1;
else
dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
}
print_bits(N, L, out, I - 1);
out.println();
f.close();
out.close();
}
public static void print_bits(int len, int ones, PrintWriter out, long index) throws Exception {
if (len == 0)
return;
if (dp[len - 1][ones] > index) {
out.print('0');
print_bits(len - 1, ones, out, index);
} else {
out.print('1');
print_bits(len - 1, ones - 1, out, index - dp[len - 1][ones]);
}
}
}