-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathN과 M (2).java
More file actions
35 lines (29 loc) · 922 Bytes
/
N과 M (2).java
File metadata and controls
35 lines (29 loc) · 922 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int[] arr;
static int n, m;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
arr = new int[m];
func(1, 0);
}
static void func(int now, int cnt) {
if (cnt == m) {
for (int i = 0; i < m; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
return;
}
for (int i = now; i <= n; i++) {
arr[cnt] = i;
func(i + 1, cnt + 1);
}
}
}