-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10844.cpp
More file actions
46 lines (40 loc) · 922 Bytes
/
10844.cpp
File metadata and controls
46 lines (40 loc) · 922 Bytes
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
// 10844. 쉬운 계단 수
// 2020.07.07
// 다이나믹 프로그래밍
#include<iostream>
using namespace std;
int d[101][10]; // d[i][j] : 끝이 j이고 길이가 i인 계단수
int main()
{
int n;
cin >> n;
for (int i = 1; i < 10; i++)
{
d[1][i] = 1; // 끝이 i이고 길이가 1인 계단수는 1개
}
for (int i = 2; i <= n; i++)
{
for (int j = 0; j <= 9; j++)
{
d[i][j] = 0;
if (j - 1 >= 0)
{
d[i][j] += d[i - 1][j - 1];
}
if (j + 1 <= 9)
{
d[i][j] += d[i - 1][j + 1];
}
d[i][j] %= 1000000000;
}
}
long long ans = 0;
// 길이가 n인 끝이 0~9인 계단수를 더함
for (int i = 0; i <= 9; i++)
{
ans += d[n][i];
ans %= 1000000000;
}
cout << ans << endl;
return 0;
}