공부기록/백준
[백준] 2407번 조합
메델
2024. 2. 3. 00:21
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static int n, m;
static BigInteger[][] arr = new BigInteger[105][105];
static BigInteger combination(int n, int m) {
if (arr[n][m] != null)
return arr[n][m];
if (m == 0 || m == n)
return BigInteger.ONE;
return arr[n][m] = combination(n - 1, m - 1).add(combination(n - 1, m));
}
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
n = kb.nextInt();
m = kb.nextInt();
System.out.println(combination(n, m));
}
}
long으로 썼는데 4퍼센트에서 틀렸다고 나오는 분들은 BigInteger로 바꾸시는 걸 추천합니다.