Skip to content

Commit 259a2bd

Browse files
committed
생명보험
1 parent aaa971f commit 259a2bd

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ output.txt
66
main
77
main.cpp
88

9-
.idea
9+
.idea
10+
11+
ALGORITHMS/**/*.md

ALGORITHMS/생명보험.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function solution(table) {
2+
const list = table.map((t) =>
3+
parseInt(
4+
Array.from(t)
5+
.map((x) => (x === "X" ? 0 : 1))
6+
.join("")
7+
.toString(2),
8+
2
9+
)
10+
);
11+
12+
let result = 8;
13+
const des = Math.pow(2, table[0].length) - 1;
14+
const dfs = (list, acc, dep) => {
15+
if (dep > result) return;
16+
if (acc === des && dep < result) {
17+
result = dep;
18+
return;
19+
}
20+
21+
list.forEach((l, i) => {
22+
const temp = list.slice();
23+
temp.splice(i, 1);
24+
dfs(temp, acc | l, dep + 1);
25+
});
26+
};
27+
28+
dfs(list, 0, 0);
29+
30+
return result;
31+
}

0 commit comments

Comments
 (0)