Repository navigation
Expand file tree
/
Copy pathcard_place.java
More file actions
55 lines (43 loc) · 1.54 KB
/
Copy pathcard_place.java
File metadata and controls
55 lines (43 loc) · 1.54 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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashSet;
public class card_place {
static HashSet<String> set = new HashSet<String>();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int card_cnt = Integer.parseInt(br.readLine()); // 카드 개수
int choice_cnt = Integer.parseInt(br.readLine()); // 뽑을 카드 수
int[] card = new int[card_cnt]; // 카드 배열
boolean[] visited = new boolean[card_cnt];
int[] arr = new int[card_cnt];
for(int i = 0; i < card_cnt; i++) {
card[i] = Integer.parseInt(br.readLine());
}
com(card, visited, arr, 0, card_cnt,choice_cnt);
bw.write(Integer.toString(set.size()));
bw.flush();
bw.close();
br.close();
}
public static void com(int[] card, boolean[] visited, int[] arr,int depth, int card_cnt, int choice_cnt) {
if(depth == choice_cnt) {
String str="";
for(int i = 0; i < arr.length;i++)
str += arr[i];
set.add(str);
return;
}
for(int i = 0; i < card_cnt; i++) {
if(visited[i] == false) {
visited[i] = true;
arr[depth] = card[i];
com(card, visited, arr, depth + 1, card_cnt,choice_cnt);
visited[i] = false;
}
}
}
}