-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab002_recursive
More file actions
65 lines (52 loc) · 1.19 KB
/
lab002_recursive
File metadata and controls
65 lines (52 loc) · 1.19 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.*;
/**
* Lab 002
* @version 1.0
* @author Sanghwan Lee
* @이 코드는 국민대학교 이상환 교수님의 코드를 기반으로 하여 만들어졌습니다.
* @id 20261234
*/
public class Lab002 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(true) {
//System.err.println("Enter n m : ");
int n = in.nextInt();
int m = in.nextInt();
if(n == 0)
break;
System.out.println("Combi(" + n + ", " + m + ")");
System.out.println("Combination(" +
n + ", " + m + ") : " +
Combi(n, m));
}
}
static int Combi(int n, int m) {
int sum = 0;
if(n==m || m == 0){
return 1;
}
else if( n-1==m){
n--;
System.out.println("Combi(" + n + ", " + m + ")");
sum++;
}
else{
n--;
System.out.println("Combi(" + n + ", " + m + ")");
sum += Combi(n,m);
}
if(m != 0){
m--;
if(m == 0){
System.out.println("Combi(" + n + ", " + m + ")");
sum++;
}
else{
System.out.println("Combi(" + n + ", " + m + ")");
sum += Combi(n,m);
}
}
return sum;
}
}