Skip to content

Commit 7893904

Browse files
committed
99차 2번 문제풀이
1 parent 7480209 commit 7893904

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

live9/test99/문제2/조진우.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require("fs");
22
const input = fs
3-
.readFileSync("./input.txt", "utf8")
4-
// .readFileSync("/dev/stdin", "utf8")
3+
// .readFileSync("./input.txt", "utf8")
4+
.readFileSync("/dev/stdin", "utf8")
55
.toString()
66
.trim()
77
.split("\n")
@@ -10,29 +10,29 @@ const input = fs
1010
function solution(input) {
1111
const [N, M] = input[0];
1212
const arr = input[1];
13-
arr.sort((a, b) => a - b); // 사전 순 출력을 위해 정렬
13+
arr.sort((a, b) => a - b);
1414

15-
const visited = Array(N).fill(false);
16-
const path = [];
15+
const used = Array(N).fill(false);
16+
const result = [];
1717

1818
function dfs(depth) {
1919
if (depth === M) {
20-
console.log(path.join(" ")); // 바로 출력!
20+
console.log(result.join(" "));
2121
return;
2222
}
2323

2424
for (let i = 0; i < N; i++) {
25-
if (visited[i]) continue;
25+
if (used[i]) continue;
2626

27-
visited[i] = true;
28-
path.push(arr[i]);
27+
used[i] = true;
28+
result.push(arr[i]);
2929
dfs(depth + 1);
30-
path.pop();
31-
visited[i] = false;
30+
result.pop();
31+
used[i] = false;
3232
}
3333
}
3434

35-
dfs(0); // 시작
35+
dfs(0);
3636
}
3737

3838
solution(input);

0 commit comments

Comments
 (0)