-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ02020.java
46 lines (42 loc) · 1.26 KB
/
J02020.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
39
40
41
42
43
44
45
46
import java.util.Scanner;
import java.util.Vector;
public class J02020 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
ans = res(n, k);
System.out.println();
System.out.println("Tong cong co " + ans.size() + " to hop");
}
static Vector<Integer> tmp = new Vector<>();
static Vector<Vector<Integer>> ans = new Vector<>();
public static void LKTH(int n, int left, int k) {
if (k == 0) {
ans.add(tmp);
/*
* J02020
* for (int i = 0; i < tmp.size(); i++) {
* System.out.print(tmp.get(i) + " ");
* }
* System.out.println();
* return;
* System.out.println();
* return;
*/
for (int i = 0; i < tmp.size(); i++) {
System.out.print(tmp.get(i));
}
System.out.print(" ");
}
for (int i = left; i <= n; i++) {
tmp.add(i);
LKTH(n, i + 1, k - 1);
tmp.remove(tmp.size() - 1);
}
}
public static Vector<Vector<Integer>> res(int n, int k) {
LKTH(n, 1, k);
return ans;
}
}