-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.java
More file actions
47 lines (37 loc) · 1.17 KB
/
Program.java
File metadata and controls
47 lines (37 loc) · 1.17 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
package practice.temp;
import java.io.*;
import java.util.*;
public class Program {
public static void main(String[] args) {
input = new int[] {1, 2, 3};
isSelected = new boolean[N];
makeSubset(0);
}
static final int N = 3;
static int[] input;
static boolean[] isSelected;
static void makeSubset(int cnt) {
for (int n = 0; n < cnt; n++) System.out.print("\t");
System.out.printf("makeSubset(cnt: %d)\n", cnt);
for (int n = 0; n < cnt; n++) System.out.print("\t");
System.out.println("input = " + Arrays.toString(input));
for (int n = 0; n < cnt; n++) System.out.print("\t");
System.out.println("isSelected = " + Arrays.toString(isSelected));
if (cnt == N) {
// 부분 집합 완성
List<Integer> subset = new ArrayList<>();
for (int i = 0; i < N; i++) {
if (isSelected[i]) subset.add(input[i]);
}
for (int n = 0; n < cnt; n++) System.out.print("\t");
System.out.println("부분 집합 완성 = " + subset);
System.out.println();
return;
}
System.out.println();
isSelected[cnt] = true;
makeSubset(cnt + 1);
isSelected[cnt] = false;
makeSubset(cnt + 1);
}
}