백준 9095번 (DB)

김경욱·2025년 9월 30일

백준

목록 보기
93/121

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

import java.util.*;

import static java.util.Collections.*;

public class Main {

public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int N = Integer.parseInt(br.readLine());

   int[] dp = new int[12];

   dp[1] = 1;
   dp[2] = 2;
   dp[3] = 4;

   for (int j = 4; j <=11; j++)
   {
       dp[j] = dp[j-1] + dp[j-2] + dp[j-3];
   }



   for (int i = 0 ; i < N; i++)
   {
       int M = Integer.parseInt(br.readLine());

       System.out.println(dp[M]);



   }

}
}

dp를 통해서 구하는게 신선했다.

0개의 댓글