-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ02021
34 lines (32 loc) · 926 Bytes
/
J02021
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
package test;
import java.util.Scanner;
public class J02021{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int s = 0;
int a[] = new int[k + 1];
for (int i = 1; i <= k; i++)
a[i] = i;
while (true) {
s++;
int ok = 0;
for (int i = 1; i <= k; i++)
System.out.print(a[i]);
System.out.print(" ");
for (int i = k; i >= 1; i--) {
if (a[i] != n - k + i) {
ok = 1;
a[i]++;
for (int j = i + 1; j <= k; j++)
a[j] = a[j - 1] + 1;
break;
}
}
if (ok == 0)
break;
}
System.out.printf("\nTong cong co %d to hop", s);
}
}