-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1759.java
More file actions
61 lines (56 loc) · 1.73 KB
/
Copy path1759.java
File metadata and controls
61 lines (56 loc) · 1.73 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
56
57
58
59
60
61
// https://www.acmicpc.net/problem/1759
// BOJ 1759 암호 만들기
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
static List<String> list;
static int l, c;
static StringBuilder sb;
static boolean[] visited;
public static void main(String[] args) throws IOException {
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(scan.readLine());
l = Integer.parseInt(st.nextToken());
c = Integer.parseInt(st.nextToken());
st = new StringTokenizer(scan.readLine());
list = new ArrayList<>();
for(int i=0; i<c; i++){
list.add(st.nextToken());
}
Collections.sort(list);
sb = new StringBuilder();
visited = new boolean[c];
//System.out.println(list);
dfs();
}
public static void dfs(){
if(sb.length() == l){
if(check(sb.toString()))
System.out.println(sb);
return;
}
for(int i=0; i<c; i++){
if(sb.length() != 0 &&
sb.charAt(sb.length()-1) > list.get(i).charAt(0))
continue;
if(visited[i]) continue;
visited[i] = true;
sb.append(list.get(i));
dfs();
visited[i] = false;
sb.deleteCharAt(sb.length()-1);
}
}
public static boolean check(String str){
String moem = "aeiou";
int count = 0;
for(int i=0; i<str.length(); i++){
if(moem.indexOf(str.charAt(i)) != -1)
count++;
}
if(count >= 1 && str.length() - count >= 2)
return true;
else return false;
}
}