Skip to content

Commit edd1e15

Browse files
authored
[20250912] PGM / LV2 / 비밀 코드 해독 / 김수연
1 parent 8b224b0 commit edd1e15

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
static int answer = 0;
5+
public int solution(int n, int[][] q, int[] ans) {
6+
List<Integer> list = new LinkedList<>();
7+
dfs(n, 1, list, q, ans);
8+
9+
return answer;
10+
}
11+
12+
private void dfs(int n, int idx, List<Integer> list, int[][] q, int[] ans) {
13+
if (list.size() == 5) {
14+
if(check(list, q, ans)) {
15+
answer++;
16+
}
17+
return;
18+
}
19+
for (int i = idx; i <= n; i++) {
20+
list.add(i);
21+
dfs(n, i+1, list, q, ans);
22+
list.remove(list.size() - 1);
23+
}
24+
}
25+
26+
private boolean check(List<Integer> list, int[][] q, int[] ans) {
27+
int idx = 0;
28+
for (int[] n : q) {
29+
int cnt = 0;
30+
for (int val : n) {
31+
if (list.contains(val)) cnt++;
32+
}
33+
if (cnt != ans[idx]) return false;
34+
idx++;
35+
}
36+
return true;
37+
}
38+
}
39+
```

0 commit comments

Comments
 (0)