-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_15655
More file actions
45 lines (41 loc) · 1.37 KB
/
BAEKJOON_15655
File metadata and controls
45 lines (41 loc) · 1.37 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
import java.io.*;
import java.sql.Array;
import java.util.*;
public class Main {
static boolean[] c=new boolean[10];
static int[] a=new int[10];
static int[] num;
public static StringBuilder recursion(int index,int start,int N ,int M){
if(index==M){
StringBuilder sb =new StringBuilder();
for(int i=0; i<M; i++){
sb.append(num[a[i]]+" ");
}
sb.append("\n");
return sb;
}
StringBuilder ans = new StringBuilder();
for(int i=start; i<N; i++){
if(c[i])continue;
c[i]=true;
a[index]=i;
ans.append(recursion(index+1,i+1,N,M));
c[i]=false;
}
return ans;
}
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());
num = new int[N];
st =new StringTokenizer(br.readLine());
for(int i=0; i<N; i++){
num[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(num);
System.out.println(recursion(0,0,N,M));
}
}