Skip to content

Commit ef6d0ae

Browse files
[BOJ] 15650 N과 M (2) (S3)
1 parent d36dc5c commit ef6d0ae

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

서정우/4주차/260119.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// https://www.acmicpc.net/problem/15650
2+
3+
const fs = require("fs");
4+
const filePath = process.platform === "linux" ? "/dev/stdin" : "dev/stdin.txt";
5+
const input = fs.readFileSync(filePath).toString().trim().split("\n");
6+
7+
const [N, M] = input[0].split(" ").map(Number);
8+
9+
const result = [];
10+
11+
const backtracking = (arr) => {
12+
if (arr.length !== M) {
13+
for (let i = arr.at(-1) + 1; i <= N; i++) {
14+
arr.push(i);
15+
backtracking(arr);
16+
arr.pop();
17+
}
18+
} else {
19+
result.push(arr.join(" "));
20+
}
21+
};
22+
23+
for (let i = 1; i <= N; i++) {
24+
const arr = [i];
25+
backtracking(arr);
26+
}
27+
28+
console.log(result.join("\n"));

0 commit comments

Comments
 (0)