-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10844.java
47 lines (35 loc) · 1.03 KB
/
10844.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
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] arr = new int[n+1][10];
for(int i=1; i<10; i++)
arr[1][i] = 1;
int mod = 1000000000;
for(int i=2; i<=n; i++) {
for(int j=0; j<10; j++) {
if(j==0) {
arr[i][1] += arr[i-1][j];
arr[i][1] %= mod;
}
else if(j==9) {
arr[i][8] += arr[i-1][j];
arr[i][8] %= mod;
}
else {
arr[i][j-1] += arr[i-1][j];
arr[i][j+1] += arr[i-1][j];
arr[i][j-1] %= mod;
arr[i][j+1] %= mod;
}
}
}
int answer = 0;
for(int i=0; i<10; i++) {
answer += arr[n][i];
answer %= mod;
}
System.out.println(answer % mod);
}
}