-
Notifications
You must be signed in to change notification settings - Fork 0
/
prob1759.java
62 lines (52 loc) · 1.37 KB
/
prob1759.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
58
59
60
61
62
package baekjoon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
//백준 1759 암호 만들기
public class prob1759 {
private static ArrayList<String> answer;
private static boolean judge(boolean[] visited,char[] string) {
int num1 = 0;
int num2 = 0;
for (int i = 0; i < string.length; i++) {
if(!visited[i]) continue;
if(string[i]=='a' || string[i]=='e' || string[i]=='i' || string[i]=='o' || string[i]=='u') num1++;
else num2++;
}
if(num1>=1 && num2>=2) return true;
else return false;
}
private static void combi(int n,int r,boolean[] visited,int start,char[] string) {
if(r==0) {
if(judge(visited,string)) {
String tmp = "";
for (int i = 0; i < n; i++) {
if(visited[i]) tmp+=string[i];
}
answer.add(tmp);
}
return;
}
for (int i = start; i < n; i++) {
visited[i] = true;
combi(n,r-1,visited,i+1,string);
visited[i] = false;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int L = sc.nextInt();
int C = sc.nextInt();
char[] string = new char[C];
for (int i = 0; i < C; i++) {
string[i] = sc.next().charAt(0);
}
Arrays.sort(string);
answer = new ArrayList<>();
boolean[] visited = new boolean[C];
combi(C,L,visited,0,string);
for (int i = 0; i < answer.size(); i++) {
System.out.println(answer.get(i));
}
}
}