-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp10844.java
More file actions
44 lines (38 loc) · 1.14 KB
/
p10844.java
File metadata and controls
44 lines (38 loc) · 1.14 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.*;
public class p10844 {
static Long[][] dp;
static int N;
final static long MOD = 1000000000;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
dp = new Long[N + 1][10];
for (int i = 0; i < 10; i++) {
dp[1][i] = 1L;
}
long result = 0;
for (int i = 1; i <= 9; i++) {
result += recur(N, i);
}
System.out.println(result % MOD);
}
static long recur(int digit, int val) {
if (digit == 1) {
return dp[digit][val];
}
if (dp[digit][val] == null) {
if (val == 0) {
dp[digit][val] = recur(digit - 1, 1);
}
else if(val == 9) {
dp[digit][val] = recur(digit - 1, 8);
}
else {
dp[digit][val] = recur(digit - 1, val - 1) + recur(digit - 1, val + 1);
}
}
return dp[digit][val] % MOD;
}
}