Skip to content

Commit 16da70c

Browse files
committed
issue 15649
1 parent 9e8af43 commit 16da70c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/backjoon/_15649.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package backjoon;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
public class _15649 {
9+
public static int[] arr;
10+
public static boolean[] visit;
11+
public static StringBuilder sb = new StringBuilder();
12+
13+
public static void main(String[] args) throws IOException {
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
StringTokenizer st = new StringTokenizer(br.readLine());
16+
// memory runtime
17+
int N = Integer.parseInt(br.readLine());
18+
int M = Integer.parseInt(st.nextToken());
19+
20+
arr = new int[M];
21+
visit = new boolean[N];
22+
dfs(N, M, 0);
23+
System.out.println(sb);
24+
}
25+
26+
public static void dfs(int N, int M, int depth) {
27+
if (depth == M) {
28+
for (int val : arr) {
29+
sb.append(val).append(' ');
30+
}
31+
sb.append('\n');
32+
return;
33+
}
34+
35+
for (int i = 0; i < N; i++) {
36+
if (!visit[i]) {
37+
visit[i] = true;
38+
arr[depth] = i + 1;
39+
dfs(N, M, depth + 1);
40+
visit[i] = false;
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy