We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5de46e6 commit 43de5aaCopy full SHA for 43de5aa
1 file changed
이용훈/8주차/260220.js
@@ -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
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