We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent af473ff commit a46e6e6Copy full SHA for a46e6e6
1 file changed
live9/test99/문제2/황장현.js
@@ -0,0 +1,38 @@
1
+const input = require('fs')
2
+ .readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3
+ .toString()
4
+ .trim()
5
+ .split('\n')
6
+ .map((el) => el.split(' ').map(Number));
7
+
8
+function solution(input) {
9
+ const [N, M] = input[0];
10
+ const number = input[1].sort((a, b) => a - b);
11
12
+ const visited = Array(N).fill(false);
13
+ const path = [];
14
+ const result = [];
15
16
+ function dfs(depth) {
17
+ if (depth === M) {
18
+ result.push(path.join(' '));
19
+ return;
20
+ }
21
22
+ for (let i = 0; i < N; i++) {
23
+ if (!visited[i]) {
24
+ visited[i] = true;
25
+ path.push(number[i]);
26
+ dfs(depth + 1);
27
+ path.pop();
28
+ visited[i] = false;
29
30
31
32
33
+ dfs(0);
34
35
+ return result.join('\n');
36
+}
37
38
+console.log(solution(input));
0 commit comments