Skip to content

Commit

Permalink
#8 22.11.10 > 바둑이 승차
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Nov 10, 2022
1 parent 0c82a24 commit 7511f7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/inf/recursive,dfs/6_rere.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

function solution(c, arr) {
let answer = 0;

function dfs(L, sum) {
// c를 넘으면 return
if (sum > c) return;
if (L === arr.length) answer = Math.max(answer, sum);
else {
// 바둑이를 태움
dfs(L + 1, sum + arr[L]);

// 태우지 않음
dfs(L + 1, sum);
}
}
dfs(0, 0);
return answer;
}

let arr = [81, 58, 42, 33, 61];
console.log(solution(259, arr));
2 changes: 1 addition & 1 deletion src/inf/recursive,dfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
| 3 || 22.11.09 |
| 4 | X | 22.11.10😥 |
| 5 | X | 22.11.10😥 |
| 6 || O |
| 6 || 22.11.10😥 |
| 7 || O |
| 8 | X | O |
| 9 || O |
Expand Down

0 comments on commit 7511f7d

Please sign in to comment.