Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d9a1850

Browse files
committed
고다혜: [PG] 64064 불량 사용자_241127
1 parent c3f1825 commit d9a1850

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎Programmers/Level3/DH_64064.java‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java.util.*;
2+
3+
/*
4+
* 불량 사용자
5+
*/
6+
7+
public class DH_64064 {
8+
static int answer;
9+
static String[] sel;
10+
static HashSet<Integer> set;
11+
12+
static int solution(String[] user_id, String[] banned_id) {
13+
set = new HashSet<Integer>();
14+
sel = new String[banned_id.length];
15+
16+
for(int i = 0; i < banned_id.length; i++) banned_id[i] = banned_id[i].replaceAll("\\*", "[a-z0-9]");
17+
18+
func(0, 0, 0, user_id, banned_id, banned_id.length);
19+
return answer;
20+
}
21+
22+
static void func(int depth, int idx, int status, String[] userId, String[] bannedId, int bannedLength) {
23+
if(depth == bannedLength) {
24+
if(!set.contains(status)) {
25+
set.add(status);
26+
answer += 1;
27+
}
28+
return;
29+
}
30+
31+
for(int i = idx; i < userId.length; i++) {
32+
if((status & (1 << i)) > 0) continue; // 이미 불량 사용자 리스트에 있는 회원이라면 continue
33+
if(!userId[i].matches(bannedId[depth])) continue;
34+
35+
status |= (1 << i); // i 번째 회원 비트 키기
36+
sel[depth] = userId[i];
37+
38+
int nextIdx = 0;
39+
40+
// banned_id[depth]와 banned_id[depth]가 같은 경우
41+
if(depth < bannedId.length - 1 && bannedId[depth].equals(bannedId[depth + 1])) nextIdx = i + 1;
42+
43+
func(depth + 1, nextIdx, status, userId, bannedId, bannedLength);
44+
status &= ~(1 << i); // i번째 회원 비트 끄기
45+
}
46+
}
47+
48+
public static void main(String[] args) {
49+
String[] user_id = {"aa", "ab", "ac", "ad", "ae", "be"};
50+
String[] banned_id = {"*b", "*c", "*d", "*e", "a*", "**"};
51+
52+
System.out.println(solution(user_id, banned_id));
53+
}
54+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /