-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJava_15655.java
More file actions
41 lines (36 loc) · 976 Bytes
/
Java_15655.java
File metadata and controls
41 lines (36 loc) · 976 Bytes
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
import java.util.Arrays;
import java.util.Scanner;
public class Java_15655 {
static int[] num, order;
static int N, M;
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
M = sc.nextInt();
num = new int[N];
order = new int[M];
for (int i = 0; i < N; i++) {
num[i] = sc.nextInt();
}
Arrays.sort(num);
perm(0);
System.out.print(sb);
}
static void perm(int cnt) {
if (cnt == M) {
for (int a : order) {
sb.append(a).append(" ");
}
sb.deleteCharAt(sb.lastIndexOf(" "));
sb.append("\n");
return;
}
for (int i = 0; i < N; i++) {
if(cnt==0|| order[cnt-1]<num[i]){
order[cnt]=num[i];
perm(cnt+1);
}
}
}
}