Skip to content

Commit 1c21f26

Browse files
committed
[Silver I] Title: 쉬운 계단 수, Time: 104 ms, Memory: 14236 KB -BaekjoonHub
1 parent 8b9a21f commit 1c21f26

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# [Silver I] 쉬운 계단 수 - 10844
2+
3+
[문제 링크](https://www.acmicpc.net/problem/10844)
4+
5+
### 성능 요약
6+
7+
메모리: 14236 KB, 시간: 104 ms
8+
9+
### 분류
10+
11+
다이나믹 프로그래밍
12+
13+
### 제출 일자
14+
15+
2025년 5월 12일 17:45:37
16+
17+
### 문제 설명
18+
19+
<p>45656이란 수를 보자.</p>
20+
21+
<p>이 수는 인접한 모든 자리의 차이가 1이다. 이런 수를 계단 수라고 한다.</p>
22+
23+
<p>N이 주어질 때, 길이가 N인 계단 수가 총 몇 개 있는지 구해보자. 0으로 시작하는 수는 계단수가 아니다.</p>
24+
25+
### 입력
26+
27+
<p>첫째 줄에 N이 주어진다. N은 1보다 크거나 같고, 100보다 작거나 같은 자연수이다.</p>
28+
29+
### 출력
30+
31+
<p>첫째 줄에 정답을 1,000,000,000으로 나눈 나머지를 출력한다.</p>
32+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
static int n, ans , MOD;
6+
static int[][] dp;
7+
8+
public static void main(String[] args) throws Exception{
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
n = Integer.parseInt(br.readLine());
11+
dp = new int[n][10];
12+
MOD = 1000000000;
13+
for(int i = 0; i < n; i++) Arrays.fill(dp[i], -1);
14+
for (int i = 1; i < 10; i++) {
15+
ans += recur(1, i);
16+
ans %= MOD;
17+
}
18+
19+
System.out.println(ans);
20+
}
21+
22+
static int recur(int cnt, int now){
23+
if(cnt == n)return 1;
24+
if(dp[cnt][now] != -1) return dp[cnt][now];
25+
26+
int rot = 0;
27+
if(0 < now) rot += recur(cnt + 1, now - 1);
28+
if(now < 9) rot += recur(cnt + 1, now + 1);
29+
return dp[cnt][now] = rot % MOD;
30+
}
31+
}

0 commit comments

Comments
 (0)