-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermMain.java
More file actions
45 lines (39 loc) · 802 Bytes
/
PermMain.java
File metadata and controls
45 lines (39 loc) · 802 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
44
45
package algorithm;
import java.util.*;
public class PermMain {
static int N = 4, R = 3, C;
static int[] a = { 1, 2, 3, 4 }, b = new int[R];
static boolean[] v = new boolean[N];
static void perm(int cnt) {
if (cnt == R) {
System.out.println(Arrays.toString(b));
C++;
return;
}
for (int i = 0; i < N; i++) {
if (v[i])
continue;
v[i] = true;
b[cnt] = a[i];
perm(cnt + 1);
v[i] = false;
}
}
static void comb(int cnt, int start) {
if (cnt == R) {
System.out.println(Arrays.toString(b));
C++;
return;
}
for (int i = start; i < N; i++) {
b[cnt] = a[i];
comb(cnt + 1, i + 1);
}
}
public static void main(String[] args) throws Exception {
C = 0;
// perm(0); // 순서중요
comb(0, 0); // 순서무관
System.out.println(C);
}
}