Skip to content

Commit 43de5aa

Browse files
committed
[PGS] 87946 피로도 (Lv.2)
1 parent 5de46e6 commit 43de5aa

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

이용훈/8주차/260220.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function solution(k, dungeons) {
2+
let answer = 0;
3+
let n = dungeons.length;
4+
let ch = Array.from({length:n}, () => 0);
5+
6+
const path = [];
7+
const dfs = (L) => {
8+
if(L === n) {
9+
let my = k;
10+
let cnt = 0;
11+
for(let i of path) {
12+
const [min, cost] = dungeons[i];
13+
14+
if(my >= min) {
15+
my -= cost;
16+
cnt++;
17+
} else {
18+
continue;
19+
}
20+
}
21+
22+
answer = Math.max(answer, cnt);
23+
} else {
24+
for(let i = 0; i < n; i++) {
25+
if(ch[i] === 0) {
26+
ch[i] = 1;
27+
path.push(i);
28+
dfs(L + 1);
29+
path.pop(i);
30+
ch[i] = 0;
31+
}
32+
}
33+
}
34+
}
35+
36+
dfs(0)
37+
return answer;
38+
}

0 commit comments

Comments
 (0)