Skip to content

Commit 02e40b1

Browse files
authored
[20251114] PGM / LV2 / 피로도 / 이인희
1 parent a2e0ac9 commit 02e40b1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
private int maxCount = 0;
6+
7+
public int solution(int k, int[][] dungeons){
8+
boolean[] visited = new boolean[dungeons.length];
9+
dfs(k, dungeons, visited, 0);
10+
return maxCount;
11+
}
12+
13+
private void dfs(int cur, int[][] dungeons, boolean[] visited, int count){
14+
if(count > maxCount){
15+
maxCount = count;
16+
}
17+
for(int i = 0; i < dungeons.length; i++){
18+
if(visited[i]) {
19+
continue;
20+
}
21+
int required = dungeons[i][0];
22+
int cost = dungeons[i][1];
23+
if(cur < required){
24+
continue;
25+
}
26+
visited[i] = true;
27+
dfs(cur - cost, dungeons, visited, count + 1);
28+
visited[i] = false;
29+
}
30+
}
31+
}
32+
33+
```

0 commit comments

Comments
 (0)