씨니 2022. 3. 20. 19:17
728x90

▶ 9095번 문제

 

▶풀이 방법

import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		
		int[] dp = new int[11];
		
		dp[1] = 1;
		dp[2] = 2;
		dp[3] = 4;
		
		for(int j = 0; j < count; j++) {
			int num = Integer.parseInt(br.readLine());
			for(int i = 4; i <= num; i++) {
				dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
			}
			System.out.println(dp[num]);
		}
		br.close();
	}
}

 

728x90