[Java] 백준 - 1,2,3 더하기(9095)

1, 2, 3 더하기

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int[] arr = new int[11];
        arr[1] = 1;
        arr[2] = 2;
        arr[3] = 4;
        
        for(int i=4;i<11; i++){
            arr[i] = arr[i-3]+arr[i-2]+arr[i-1];
        }
        
        int T = Integer.parseInt(br.readLine());
        int[] N = new int[T];
        
        for(int i=0; i<T; i++)
            N[i] = Integer.parseInt(br.readLine());
        
        for(int i : N)
            System.out.println(arr[i]);
        
        
    }
}

좋은 웹페이지 즐겨찾기