Skip to content

Commit 3237829

Browse files
author
Eric
committed
95차 1번 문제풀이
1 parent e8690c4 commit 3237829

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

live9/test95/문제1/황장현.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function solution(k, dungeons) {
2+
let maxDepth = 0;
3+
4+
function DFS(현재피로도, currentDepth, visited) {
5+
maxDepth = Math.max(maxDepth, currentDepth);
6+
7+
for (let i = 0; i < dungeons.length; i++) {
8+
if (visited[i]) continue;
9+
10+
const [최소필요피로도, 소모피로도] = dungeons[i];
11+
12+
if (현재피로도 >= 최소필요피로도) {
13+
visited[i] = true;
14+
DFS(현재피로도 - 소모피로도, currentDepth + 1, visited);
15+
visited[i] = false;
16+
}
17+
}
18+
}
19+
20+
const visited = Array(dungeons.length).fill(false);
21+
DFS(k, 0, visited);
22+
23+
return maxDepth;
24+
}
25+
26+
console.log(
27+
solution(80, [
28+
[80, 20],
29+
[50, 40],
30+
[30, 10],
31+
])
32+
);

0 commit comments

Comments
 (0)