-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10844.java
40 lines (32 loc) · 1.07 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static long[][] dp;
static final int MOD = 1000000000;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
dp = new long[N + 1][10];
br.close();
for(int i = 0; i <= 9; i++) {
dp[1][i] = 1;
}
long answer = 0;
for(int i = 1; i <= 9; i++) {
answer += getCount(N, i);
}
System.out.println(answer % MOD);
}
public static long getCount(int pos, int num) {
if(pos == 1) return dp[pos][num];
if(dp[pos][num] == 0) {
if(num == 0) dp[pos][num] = getCount(pos - 1, 1);
else if(num == 9) dp[pos][num] = getCount(pos - 1, 8);
else {
dp[pos][num] = getCount(pos - 1, num - 1) + getCount(pos - 1, num + 1);
}
}
return dp[pos][num] % MOD;
}
}