Skip to content

Commit b0df0ff

Browse files
authored
[20251026] PGM / LV2 / 피로도 / 강신지
1 parent 54693e8 commit b0df0ff

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

ksinji/202510/26 PGM 피로도.md

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

0 commit comments

Comments
 (0)