문제링크
https://www.acmicpc.net/problem/9095
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
int arr[] = new int[T];
int max = Integer.MIN_VALUE;
for(int t=0;t<T;t++) {
arr[t] = sc.nextInt();
if(max<arr[t]) max = arr[t];
}
int d[] = new int[max+1];
d[0] = 0;
if(max>=1) d[1] =1;
if(max>=2) d[2] =2;
if(max>=3) d[3] =4;
for(int i=4;i<=max;i++) {
d[i] = d[i-1] + d[i-2] + d[i-3];
}
//System.out.println(Arrays.toString(d));
for(int t=0;t<T;t++) System.out.println(d[arr[t]]);
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[JAVA]백준_11726_2*N타일링 (0) | 2021.03.24 |
---|---|
[JAVA]백준_11727_2*N 타일링2 (0) | 2021.03.24 |
[JAVA]백준_2748_피보나치수2 (0) | 2021.03.24 |
[JAVA]백준_9461_파도반 수열 (0) | 2021.03.24 |
[JAVA]백준_1463_1로만들기 (0) | 2021.03.24 |