상세 컨텐츠

본문 제목

백준 11050번

백준 알고리즘 풀이

by 발발개발 2021. 4. 5. 17:46

본문

원본 : www.acmicpc.net/problem/11050

 

11050번: 이항 계수 1

첫째 줄에 \(N\)과 \(K\)가 주어진다. (1 ≤ \(N\) ≤ 10, 0 ≤ \(K\) ≤ \(N\))

www.acmicpc.net

 

풀이

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {

	public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	public static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

	public static void main(String[] args) throws Exception {
		String str = reader.readLine();
		writer.write(fnBinomial(Integer.parseInt(str.split(" ")[0]), Integer.parseInt(str.split(" ")[1])) + "");
		writer.flush();
	}
	
	public static int factorial(int num) {
		if (num <= 1) {
			return 1;
		} else {
			return num * factorial(num - 1);
		}
	}
	
	public static int fnBinomial(int n, int r) {
		return factorial(n) / factorial(r) / factorial(n - r);
	}
	
}

'백준 알고리즘 풀이' 카테고리의 다른 글

백준 1010번  (0) 2021.04.06
백준 11051번  (0) 2021.04.06
백준 3036번  (0) 2021.04.05
백준 2981번  (0) 2021.04.05
백준 1934번  (0) 2021.04.05

관련글 더보기

댓글 영역