-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_15650
More file actions
51 lines (42 loc) · 1.28 KB
/
BAEKJOON_15650
File metadata and controls
51 lines (42 loc) · 1.28 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
50
51
import java.io.*;
import java.util.*;
public class Main {
static boolean[] c;
static int[] a;
static int[][] res;
static StringBuilder sb;
static int cnt=0;
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());
int M = Integer.parseInt(st.nextToken());
c=new boolean[N+1];
a=new int[M];
sb =new StringBuilder();
recursion(0,1, N,M);
bw.write(sb.toString());
bw.flush();
bw.close();
}
public static void recursion(int index,int start,int N,int M){
if(index==M){
for (int i = 0; i < M; i++) {
System.out.print(a[i]);
if (i != M - 1) {
System.out.print(" ");
}
}
System.out.println();
return;
}
for(int i=start; i<=N; i++){
if(c[i])continue;
c[i] =true;
a[index]=i;
recursion(index+1,i+1,N,M);
c[i]=false;
}
}
}