-
Notifications
You must be signed in to change notification settings - Fork 0
/
6603.java
57 lines (44 loc) · 1.08 KB
/
6603.java
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
56
57
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
static int N;
static int[] numbers;
static int[] check;
static StringBuilder output = new StringBuilder();
public static void main(String args[]) throws Exception {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
while(true){
String []testCase = input.readLine().split(" ");
N = Integer.parseInt(testCase[0]);
if(N == 0) break;
numbers = new int[N];
check = new int[N];
for(int i=0; i<N; i++){
numbers[i] = Integer.parseInt(testCase[i+1]);
}
DFS(0,0);
output.append("\n");
}
System.out.println(output);
}
static String DFS(int head, int depth){
if(depth == 6){
output.append(print());
}
for(int i=head; i<N; i++){
check[i] = 1;
DFS(i+1, depth+1);
check[i] = 0;
}
return "";
}
static String print(){
StringBuilder result = new StringBuilder();
for(int i=0; i<N; i++){
if(check[i] == 1){
result.append(numbers[i]+" ");
}
}
return result.append("\n").toString();
}
}