https://www.acmicpc.net/problem/1759
import java.util.*;
public class Main {
public static int l, c;
public static char[] arr;
public static char[] ch;
public static boolean[] visit;
public static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
l = sc.nextInt();
c = sc.nextInt();
arr = new char[l];
ch = new char[c];
visit = new boolean[c];
for (int i = 0; i < c; i++) {
ch[i] = sc.next().charAt(0);
}
Arrays.sort(ch);
dfs(0, 0);
System.out.println(sb);
}
public static void dfs(int at, int depth) {
if (depth == l) {
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < l; i++) {
if (arr[i] == 'a' || arr[i] == 'e' || arr[i] == 'i' || arr[i] == 'o' || arr[i] == 'u') {
cnt1++;
} else
cnt2++;
}
if (cnt1 >= 1 && cnt2 >= 2) {
for (int i = 0; i < l; i++) {
sb.append(arr[i]);
}
sb.append('\n');
}
return;
}
for (int i = at; i < c; i++) {
if (!visit[i]) {
visit[i] = true;
arr[depth] = ch[i];
dfs(i + 1, depth + 1);
visit[i] = false;
}
}
}
}
'코딩테스트 > JAVA' 카테고리의 다른 글
[백준 JAVA] 1260번: DFS와 BFS - 스승님과 같이 풀어보기 (0) | 2024.07.26 |
---|---|
[백준 JAVA] 14501번: 퇴사 (0) | 2024.07.25 |
[백준 JAVA] 9095번: 1, 2, 3 더하기 (1) | 2024.07.23 |
[백준 JAVA] 1260번: DFS와 BFS (2) | 2024.07.23 |
[백준 JAVA] 6603번: 로또 (1) | 2024.07.22 |