-
Notifications
You must be signed in to change notification settings - Fork 0
/
DP_BOJ_9095_LJE.java
53 lines (49 loc) · 1016 Bytes
/
DP_BOJ_9095_LJE.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package DP;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
* 1 = 1
* -------------------> 1
*
* 2 = 2
* = 1 + 1
* -------------------> 2
*
* 3 = 3
* = 2 + 1
* = 1 + 2
* = 1 + 1 + 1
* -------------------> 4
*
* 4 = 3 + (1)->1
* = 2 + (2)->2
* = 1 + (3)->4
* -------------------> 7
*
* 5 = 3 + (2)->2
* = 2 + (3)->4
* = 1 + (4)->7
* -------------------> 13
*
* => a(n) = a(n-1) + a(n-2) + a(n-3)
*/
public class DP_BOJ_9095 {
static int[] d = new int[12];
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int TC = Integer.parseInt(br.readLine());
d[1]=1;
d[2]=2;
d[3]=4;
for (int i = 4; i <= 11; i++) {
if(d[i]==0) {
d[i] = d[i-1] + d[i-2]+ d[i-3];
}
}
for (int tc = 0; tc < TC; tc++) {
int N = Integer.parseInt(br.readLine());
System.out.println(d[N]);
} // TC end
}
}