Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
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
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준-2407번/Java] 조합 본문

Algorithm

[백준-2407번/Java] 조합

1984 2022. 11. 26. 22:29

https://www.acmicpc.net/problem/2407

 

2407번: 조합

n과 m이 주어진다. (5 ≤ n ≤ 100, 5 ≤ m ≤ 100, m ≤ n)

www.acmicpc.net

* BigInteger로 구현

* 조합 공식

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		int N = in.nextInt();
		int M = in.nextInt();

		System.out.println(factorial(N).divide(factorial(M)).divide(factorial(N-M)));

	}

	public static BigInteger factorial(int num) {
		if (num == 1)
			return new BigInteger("1");
		return new BigInteger(String.valueOf(num)).multiply(factorial(num - 1));
	}

}
728x90

'Algorithm' 카테고리의 다른 글

[Array-10/Java] 봉우리  (0) 2022.11.25
[백준-3036번/Java] 링  (0) 2022.11.23
[백준-1002번/Java] 터렛  (0) 2022.11.22
[백준-3053번/Java] 택시 기하학  (0) 2022.11.22
[백준-2477번/Java] 참외밭  (0) 2022.11.22
Comments