풀이
import java.io.*;
import java.util.*;
public class Main {
public static StringTokenizer stk;
public static StringBuffer sb = new StringBuffer();
public static HashSet<String> hs = new HashSet<>();
public static boolean[] visited;
public static String[] card;
public static int cnt = 0, n, k;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
k = Integer.parseInt(br.readLine());
card = new String[n + 1];
visited = new boolean[n + 1];
for (int i = 1; i <= n; i++) {
card[i] = br.readLine();
}
dfs(k, 1, "");
System.out.println(hs.size());
}
public static void dfs(int k, int idx, String s) {
if (k == 0) {
hs.add(s);
return;
}
if (idx > n) {
return;
}
for (int i = 1; i <= n; i++) {
if (!visited[i]) {
visited[i] = true;
dfs(k - 1, i, s + card[i]);
visited[i] = false;
}
}
}
}
'코딩 문제 > 백준' 카테고리의 다른 글
백준 - 7785번 (0) | 2021.03.15 |
---|---|
백준 - 6603번 (0) | 2021.03.15 |
백준 - 4796번 (0) | 2021.03.15 |
백준 - 2891번 (0) | 2021.03.15 |
백준 - 2890번 (0) | 2021.03.15 |