-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSum5.java
More file actions
40 lines (29 loc) · 747 Bytes
/
Copy pathSum5.java
File metadata and controls
40 lines (29 loc) · 747 Bytes
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
package dynamic;
import java.util.Scanner;
public class Sum5 {
public static void main(String[] args) {
//#15990¹ø 1,2,3 ´õÇϱâ5
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long[][] dp = new long[1000001][4];
dp[1][1] = 1;
dp[2][2] = 1;
dp[3][3] = 1;
for(int i=1; i<=1000000; i++) {
if(i>1) {
dp[i][1] = (dp[i-1][2] + dp[i-1][3])%1000000009;
}
if(i>2) {
dp[i][2] = (dp[i-2][1] + dp[i-2][3])%1000000009;
}
if(i>3) {
dp[i][3] = (dp[i-3][1] + dp[i-3][2])%1000000009;
}
}
for(int i=0; i<n; i++) {
int k = sc.nextInt();
long ans = (dp[k][1] + dp[k][2] + dp[k][3]) % 1000000009;
System.out.println(ans);
}
}
}