-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj10844.java
More file actions
44 lines (35 loc) · 1.12 KB
/
boj10844.java
File metadata and controls
44 lines (35 loc) · 1.12 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.InputStreamReader;
public class boj10844 {
static Long[][] dp;
final static long m = 1_000_000_000L;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
long ans = 0;
dp = new Long[N + 1][10];
for (int i = 0; i < 10; i++) {
dp[1][i] = 1L;
}
for (int i = 1; i <= 9; i++) {
ans += recur(N, i);
}
System.out.println(ans % m);
}
private static long recur(int index, int num) {
if (index == 1) {
return dp[index][num];
}
if (dp[index][num] == null) {
if (num == 0) {
dp[index][num] = recur(index - 1, 1);
} else if (num == 9) {
dp[index][num] = recur(index - 1, 8);
} else {
dp[index][num] = recur(index - 1, num - 1) + recur(index - 1, num + 1);
}
}
return dp[index][num] % m;
}
}