-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_15649
More file actions
49 lines (39 loc) · 1.22 KB
/
BAEKJOON_15649
File metadata and controls
49 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.io.*;
import java.util.*;
public class Main {
static StringBuilder sb =new StringBuilder();
static boolean[] c;
static int[] a;
public static void recur(int index,int N, int M){
if(index==M){
for(int i=0; i<M; i++){
sb.append(a[i]);
if(i!=M-1){
sb.append(" ");
}
}
sb.append("\n");
return;
}
for(int i=1; i<=N; i++){
if(c[i])continue;
c[i]=true;
a[index]=i;
recur(index+1,N,M);
c[i]=false;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken()); // 1 ~ N까지의 자연수
int M = Integer.parseInt(st.nextToken()); // M자리 수열
c= new boolean[N+1];
a= new int[M];
recur(0,N,M);
bw.write(sb.toString());
bw.flush();
bw.close();
}
}