-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP15651_순열.java
38 lines (33 loc) · 945 Bytes
/
P15651_순열.java
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
package net.acmicpc.순열조합;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class P15651_순열 {
static int M;
static int N;
static int[] numbers;
static StringBuilder sb;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] NM = br.readLine().split(" ");
N = Integer.parseInt(NM[0]);
M = Integer.parseInt(NM[1]);
sb = new StringBuilder();
numbers = new int[M];
permutation(0);
System.out.println(sb.toString().trim());
}
private static void permutation(int index) {
if (index == M) {
for (int v : numbers) {
sb.append(v).append(" ");
}
sb.append("\n");
return;
}
for (int i = 1; i <= N; ++i) {
numbers[index] = i;
permutation(index + 1);
}
}
}