-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDH_64064.java
More file actions
51 lines (38 loc) · 1.41 KB
/
DH_64064.java
File metadata and controls
51 lines (38 loc) · 1.41 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
import java.util.*;
/*
* 불량 사용자
*/
public class DH_64064 {
static int answer;
static HashSet<Integer> set;
static int solution(String[] user_id, String[] banned_id) {
set = new HashSet<Integer>();
for(int i = 0; i < banned_id.length; i++) banned_id[i] = banned_id[i].replaceAll("\\*", "[a-z0-9]");
func(0, 0, 0, user_id, banned_id, banned_id.length);
return answer;
}
static void func(int depth, int idx, int status, String[] userId, String[] bannedId, int bannedLength) {
if(depth == bannedLength) {
if(!set.contains(status)) {
set.add(status);
answer += 1;
}
return;
}
for(int i = idx; i < userId.length; i++) {
if((status & (1 << i)) > 0) continue; // 이미 불량 사용자 리스트에 있는 회원이라면 continue
if(!userId[i].matches(bannedId[depth])) continue;
status |= (1 << i); // i 번째 회원 비트 키기
int nextIdx = 0;
// banned_id[depth]와 banned_id[depth]가 같은 경우
if(depth < bannedId.length - 1 && bannedId[depth].equals(bannedId[depth + 1])) nextIdx = i + 1;
func(depth + 1, nextIdx, status, userId, bannedId, bannedLength);
status &= ~(1 << i); // i번째 회원 비트 끄기
}
}
public static void main(String[] args) {
String[] user_id = {"aa", "ab", "ac", "ad", "ae", "be"};
String[] banned_id = {"*b", "*c", "*d", "*e", "a*", "**"};
System.out.println(solution(user_id, banned_id));
}
}