본문 바로가기
알고리즘 문제풀이/백준

[백준 2225] 합분해(JAVA)

by 소보루:-) 2020. 4. 7.

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

 

2225번: 합분해

첫째 줄에 답을 1,000,000,000으로 나눈 나머지를 출력한다.

www.acmicpc.net

 

 

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

public class Main_bj_2225_합분해 {

	static int N,K;
	static int[][] dp;
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine()," ");
		
		N=Integer.parseInt(st.nextToken());
		K=Integer.parseInt(st.nextToken());
		dp=new int[201][201];
		for(int i=1; i<=K; i++) {
			dp[0][i]=1;
		}
		for(int i=1; i<=N; i++) {
			for(int j=1; j<=K; j++) {
				dp[i][j]=(dp[i][j-1]+dp[i-1][j])%1000000000;
			}
		}
		System.out.println(dp[N][K]);
	}

}

댓글