본문 바로가기

Backjoon

[백준 2438] 부녀회장이 될테야 (완료)

반응형
[백준 2438] 부녀회장이 될테야 (완료)



[출처 : 백준]


문제접근방법
딱히 설명할 것이 없는 문제.
초기 배열을 토대로 호마다 그리고 층마다 계산만 해주면 된다.


소스코드(JAVA)
import java.util.Scanner;
public class Solution {
       static int N = 0;
       static int K = 0;
       static int T = 0;
       public static void main(String[] args) {
              StringBuilder sb = new StringBuilder();
              Scanner sc = new Scanner(System.in);
              T = Integer.parseInt(sc.nextLine());
              for (int i = 0; i < T; i++) {
                     int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
                     K = Integer.parseInt(sc.nextLine());
                     N = Integer.parseInt(sc.nextLine());
                     for (int k = 0; k < K; k++) {
                           for (int n = N; n >= 1; n--) {
                                  int sum = 0;
                                  for (int l = 1; l <= n; l++) {
                                         sum += arr[l];
                                  }
                                  arr[n] = sum;
                           }
                     }
                     sb.append(arr[N] + "\n");
              }
              System.out.println(sb);
       }
}



반응형