-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_10844.java
More file actions
55 lines (46 loc) ยท 1.46 KB
/
_10844.java
File metadata and controls
55 lines (46 loc) ยท 1.46 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
48
49
50
51
52
53
54
55
package backjoon;
// https://www.acmicpc.net/problem/10844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _10844 {
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];
// ์ฒซ๋ฒ์งธ ์๋ฆฟ์๋ 1๋ก ์ด๊ธฐํ
for(int i = 0; i < 10; i++) {
dp[1][i] = 1L;
}
long result = 0;
// ๋ง์ง๋ง ์๋ฆฟ์์ธ 1~9๊น์ง์ ๊ฒฝ์ฐ์ ์๋ฅผ ๋ชจ๋ ๋ํด์ค๋ค.
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];
}
// ํด๋น ์๋ฆฌ์์ val๊ฐ์ ๋ํด ํ์ํ์ง ์์์ ๊ฒฝ์ฐ
if(dp[digit][val] == null) {
// val์ด 0์ผ๊ฒฝ์ฐ ๋ค์์ 1๋ฐ์ ๋ชป์ด
if(val == 0) {
dp[digit][val] = recur(digit - 1 ,1);
}
// val์ด 1์ผ๊ฒฝ์ฐ ๋ค์์ 8๋ฐ์ ๋ชป์ด
else if(val== 9) {
dp[digit][val] = recur(digit - 1, 8);
}
// ๊ทธ ์ธ์ ๊ฒฝ์ฐ๋ val-1๊ณผ val+1 ๊ฐ์ ๊ฒฝ์ฐ์ ์๋ฅผ ํฉํ ๊ฒฝ์ฐ์ ์๊ฐ ๋จ
else {
dp[digit][val] = recur(digit - 1, val - 1) + recur(digit - 1, val + 1);
}
}
return dp[digit][val] % MOD;
}
}