-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay16.java
More file actions
35 lines (35 loc) · 818 Bytes
/
Copy pathDay16.java
File metadata and controls
35 lines (35 loc) · 818 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
import java.util.*;
public class Day16{
static void recur(String left, String right, int n, int diff){
if (n > 9) {
return;
}
if (n > 0 && (2 * Math.abs(diff) <= n))
{
if (n == 1)
{
recur(left, '0' + right, 0, diff);
recur(left, '1' + right, 0, diff);
return;
}
if (!left.equals(""))
{
recur(left + '0', right + '0', n - 2, diff);
recur(left + '0', right + '1', n - 2, diff - 1);
}
recur(left + '1', right + '0', n - 2, diff + 1);
recur(left + '1', right + '1', n - 2, diff);
}
else if (n == 0 && diff == 0) {
System.out.print(left + right + " ");
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
n*=2;
String left = "", right = "";
int diff = 0;
recur(left, right, n, diff);
}
}