Skip to content

Commit 6861a9c

Browse files
authored
Merge pull request #1264 from AlgorithmWithGod/lkhyun
[20251029] PGM / Lv2 / 피로도 / 이강현
2 parents a5434bf + 67af6c3 commit 6861a9c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
```java
2+
class Solution {
3+
static int max = 0;
4+
public int solution(int k, int[][] dungeons) {
5+
boolean[] visited = new boolean[dungeons.length];
6+
backtracking(dungeons, visited, 0, k);
7+
return max;
8+
}
9+
public void backtracking(int[][] dungeons, boolean[] visited, int cnt, int k){
10+
for(int i = 0; i<dungeons.length; i++){
11+
if(!visited[i]){
12+
if(k < dungeons[i][0]) continue;
13+
visited[i] = true;
14+
backtracking(dungeons,visited,cnt+1,k-dungeons[i][1]);
15+
visited[i] = false;
16+
}
17+
}
18+
max = Math.max(max,cnt);
19+
}
20+
}
21+
```

0 commit comments

Comments
 (0)