-
Notifications
You must be signed in to change notification settings - Fork 0
/
J02020.java
47 lines (47 loc) · 1.11 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
47
import java.util.*;
public class J02020 {
public static int[] a = new int[100];
public static int k,n;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
k = in.nextInt();
Init();
// display();
int cnt = 0;
while(!check()){
display();
Next();
cnt++;
}
display();
System.out.println("Tong cong co "+(cnt+1)+" to hop");
}
public static void Init(){
for (int i=1;i<=k;i++)
a[i] = i;
}
public static boolean check(){
for (int i=1;i<=k;i++){
if(a[i] != n-k+i)
return false;
}
return true;
}
public static void Next(){
int i = k;
while(a[i] == n-k+i)
i--;
if (i>0){
a[i] += 1;
for (int j = i+1;j<=k;j++)
a[j] = a[j-1] + 1;
}
}
public static void display(){
for (int i=1;i<=k;i++){
System.out.print(a[i]+" ");
}
System.out.println();
}
}