We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8938fca commit d503fd8Copy full SHA for d503fd8
level-2/피로도.js
@@ -0,0 +1,22 @@
1
+//https://github.com/codeisneverodd/programmers-coding-test
2
+//완벽한 정답이 아닙니다.
3
+//정답 1 - pereng11
4
+//완전 탐색, greedy O(N^2)
5
+ function solution(k, dungeons) {
6
+ let answer = 0;
7
+ const visited = new Array(dungeons.length).fill(false);
8
+ function dfs(k, total){
9
+ answer = Math.max( answer, total );
10
+ //모든 포인트를 출발점으로 전체 경우의 수 탐색
11
+ //0번 인덱스를 출발로 삼은 greedy 탐색이 끝나면 1번 인덱스를 출발점으로 ~ 마지막 인덱스까지 반복
12
+ for(let i = 0; i < dungeons.length; i++){
13
+ if(!visited[i] && dungeons[i][0] <= k){
14
+ visited[i] = true;
15
+ dfs(k - dungeons[i][1], total+1);
16
+ visited[i] = false;
17
+ }
18
19
20
+ dfs(k, 0);
21
+ return answer;
22
+}
0 commit comments