-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet Bridge
56 lines (43 loc) · 1 KB
/
Set Bridge
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
import java.util.Scanner;
public class SetBridge {
/*
* @ 2019-03-20
* @ Test case : N,M 쌍의 개수
* @ 서쪽 사이트 : N, 동쪽 사이트 : M
* @ 0 < N <= M < 30
* @ 다리끼리는 서로 겹쳐질 수 없다
*/
int setBridge(int n, int m) {
// N과 M의 경우의 수 구하기
int insert = 0;
int result = 0, i, j;
if (n == 1) {
result = m;
} else if (n == m) {
result = 1;
} else {
for (i = 0; i < n - 1; i++) {
for (j = m-n+1; j > 0; j--) {
result += j;
System.out.println("Result : " + result);
}
}
}
return result;
}
public static void main(String[] args) {
int N, M, testCase;
int result = 0;
SetBridge sb = new SetBridge();
System.out.print("Insert Test case : ");
Scanner sc = new Scanner(System.in);
testCase = sc.nextInt();
System.out.println("0 < N < = M < 30");
for (int i = 0; i < testCase; i++) {
N = sc.nextInt();
M = sc.nextInt();
result = sb.setBridge(N, M);
System.out.println(result);
}
}
}