
45656이란 수를 보자.
이 수는 인접한 모든 자리의 차이가 1이다. 이런 수를 계단 수라고 한다.
N이 주어질 때, 길이가 N인 계단 수가 총 몇 개 있는지 구해보자. 0으로 시작하는 수는 계단수가 아니다.
첫째 줄에 N이 주어진다. N은 1보다 크거나 같고, 100보다 작거나 같은 자연수이다.
첫째 줄에 정답을 1,000,000,000으로 나눈 나머지를 출력한다.
정보
목표
제약 조건
알고리즘
탐색 과정
주의 할 점
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BOJ10844 {
private static void solution() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
final int MOD = 1_000_000_000;
int N = Integer.parseInt(br.readLine());
int[][] DP = new int[N + 1][10];
for (int i = 1; i <= 9; i++) {
DP[1][i] = 1;
}
for (int i = 2; i <= N; i++) {
DP[i][0] += (DP[i - 1][1] % MOD);
for (int j = 1; j <= 8; j++) {
DP[i][j] += (DP[i - 1][j - 1] + DP[i - 1][j + 1]) % MOD;
}
DP[i][9] += (DP[i - 1][8] % MOD);
}
int result = 0;
for (int i = 0; i <= 9; i++) {
result = (result + DP[N][i]) % MOD;
}
System.out.println(result);
}
public static void main(String[] args) throws IOException {
BOJ10844.solution();
}
}
