본문 바로가기

백준

[백준] 11050 이항 계수 1 [자바]


https://shoark7.github.io/programming/algorithm/3-ways-to-get-binomial-coefficients

 

[조합론] 이항계수 알고리즘 3가지

I introduce 3 algorithms to get binomial coefficient.

shoark7.github.io

https://ko.wikipedia.org/wiki/%ED%8C%8C%EC%8A%A4%EC%B9%BC%EC%9D%98_%EC%82%BC%EA%B0%81%ED%98%95

 

파스칼의 삼각형 - 위키백과, 우리 모두의 백과사전

파스칼의 삼각형(Pascal's triangle)은 수학에서 이항계수를 삼각형 모양의 기하학적 형태로 배열한 것이다. 이것은 블레즈 파스칼에 의해 이름 붙여졌으나 이미 수세기 전에 다른 사람들에게서 연

ko.wikipedia.org


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine(), " ");
		int N = Integer.parseInt(st.nextToken());
		int K = Integer.parseInt(st.nextToken());
		int cache[][] = new int[N+1][K+1];
		bino_coef(cache, N, K);
		System.out.println(cache[N][K]);
	}
	static void bino_coef(int arr[][],int n, int k) {
		for(int i =0; i <= n; i++)
			arr[i][0] = 1;
		for(int i = 0; i <= k; i++)
			arr[i][i] = 1;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= k; j++) {
				arr[i][j] = arr[i-1][j] + arr[i-1][j-1]; //arr[0][1] = 0
			}
		}
	}
}

 

'백준' 카테고리의 다른 글

[백준] 7576 토마토 [자바]  (0) 2021.12.07
[백준] 2579 계단 오르기 [자바]  (0) 2021.12.03
[백준] 10814 나이순 정렬  (0) 2021.11.28
[백준] 2178 미로 탐색  (0) 2021.11.28
[백준] 2667 단지번호붙이기  (0) 2021.11.28