- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10844.java
More file actions
Latest commit
47 lines (35 loc) · 1.03 KB
/
Copy path10844.java
File metadata and controls
47 lines (35 loc) · 1.03 KB
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
importjava.util.*;
publicclassMain {
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
intn = sc.nextInt();
int[][] arr = newint[n+1][10];
for(inti=1; i<10; i++)
arr[1][i] = 1;
intmod = 1000000000;
for(inti=2; i<=n; i++) {
for(intj=0; j<10; j++) {
if(j==0) {
arr[i][1] += arr[i-1][j];
arr[i][1] %= mod;
}
elseif(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;
}
}
}
intanswer = 0;
for(inti=0; i<10; i++) {
answer += arr[n][i];
answer %= mod;
}
System.out.println(answer % mod);
}
}