본문 바로가기
알고리즘/DP

[백준] 2775번 부녀회장이 될테야 #Java #DP

by VIPeveloper 2022. 5. 7.
반응형
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static int [][] dp = new int[15][15];

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int tc = Integer.parseInt(br.readLine());
        for (int i = 0; i < tc; i++) {
            int n = Integer.parseInt(br.readLine());
            int m = Integer.parseInt(br.readLine());

            System.out.println(solution(n, m));
        }
    }

    private static int solution(int n, int m) {
        if(dp[n][m]>0) return dp[n][m];
        else if(n==0) return m;
        else{
            int cnt = 0;
            for (int i = 1; i <= m; i++) {
                cnt += solution(n-1,i);
            }
            return dp[n][m] = cnt;
        }
    }
}
반응형

'알고리즘 > DP' 카테고리의 다른 글

[백준] 1309번 동물원 #Java  (0) 2022.05.30
[백준] 11050번 이항 계수 1 #Java  (0) 2022.05.07
[백준] 2xN 타일링  (0) 2021.11.17
[백준] 1로 만들기  (0) 2021.11.16
[알고리즘] DP 공부해보기  (0) 2021.11.10