1. 이전에 사용했던 dp 로 이항계수 구함
2. 어라? 숫자가 높네
3. BigInteger 사용
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
import java.math.*; | |
/** | |
* https://www.acmicpc.net/problem/2407 | |
* BOJ 백준온라인져지 2407 조합 풀이 | |
*/ | |
public class Main { | |
private static BigInteger[][] arr; | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | |
String str1[] = br.readLine().split(" "); | |
int N = Integer.parseInt(str1[0]); | |
int K = Integer.parseInt(str1[1]); | |
arr = new BigInteger[N + 1][K + 1]; | |
bw.write(String.valueOf(r(N, K))); | |
bw.flush(); | |
} | |
private static BigInteger r (int n, int k) { | |
if (n == k || k == 0) return BigInteger.ONE; | |
if (arr[n][k] != null) return arr[n][k]; | |
arr[n][k] = new BigInteger("0"); | |
return arr[n][k] = arr[n][k].add(r(n - 1, k - 1)).add(r(n - 1, k)); | |
} | |
} |
문제
nCm을 출력한다.
입력
n과 m이 주어진다. (5 ≤ n ≤ 100, 5 ≤ m ≤ 100, m ≤ n)
출력
nCm을 출력한다.
'IT > 알고리즘' 카테고리의 다른 글
BOJ 백준온라인져지 9375 패션왕 신혜빈 풀이 (0) | 2018.03.05 |
---|---|
BOJ 백준온라인져지 6591 이항 쇼다운 풀이 (0) | 2018.03.03 |
BOJ 백준온라인져지 1676 팩토리얼 0의 개수 풀이 (1) | 2018.03.02 |
BOJ 2608 로마 숫자 풀이 (0) | 2018.03.02 |
BOJ 백준온라인져지 11051 이항 계수 2 풀이 (0) | 2018.03.01 |