-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLietKeToHop2.java
More file actions
42 lines (42 loc) · 1.02 KB
/
LietKeToHop2.java
File metadata and controls
42 lines (42 loc) · 1.02 KB
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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package JAVA;
import java.util.*;
/**
*
* @author khanh
*/
public class LietKeToHop2 {
public static int n;
public static int k;
public static int[] a=new int[1000];
public static int cnt=0;
public static void out(){
cnt++;
for(int i=1;i<=k;i++){
System.out.print(a[i]);
}
System.out.print(" ");
}
public static void Try(int i){
for(int j=a[i-1]+1;j<=n-k+i;j++){
a[i]=j;
if (i==k){
out();
}
else{
Try(i+1);
}
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
k=sc.nextInt();
Try(1);
System.out.println();
System.out.println("Tong cong co "+cnt+" to hop");
}
}