알고리즘/DP
[백준] 2775번 부녀회장이 될테야 #Java #DP
VIPeveloper
2022. 5. 7. 19:23
728x90
반응형
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;
}
}
}
728x90
반응형