-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStairs.java
More file actions
45 lines (32 loc) · 749 Bytes
/
Copy pathStairs.java
File metadata and controls
45 lines (32 loc) · 749 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
41
42
43
44
45
package dynamic;
import java.util.Scanner;
public class Stairs {
static final int MOD = 1000000000;
public static void main(String[] args) {
// #10844¹ø ½¬¿î °è´Ü ¼ö
long ans = 0;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long[][] dp = new long[n+1][10];
for(int i=0; i<=9; i++) {
dp[1][i] = 1;
}
for(int i=2; i<=n; i++) {
for(int j=0; j<10; j++) {
if(j==0) {
dp[i][j] = dp[i-1][1] % MOD;
}
else if(j==9) {
dp[i][j] = dp[i-1][8] % MOD;
}
else {
dp[i][j] = (dp[i-1][j-1] + dp[i-1][j+1]) % MOD;
}
}
}
for(int i=0; i<9; i++) {
ans += dp[n][i];
}
System.out.println(ans%MOD);
}
}