[BOJ] 10844 쉬운 계단 수

Time Lapse : None

10448.cpp

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
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <math.h>

using namespace std;

#define mod 1000000000
int N;
long long ans=0;
long long dp[101][10];

long long func(int num, int length)
{
long long &ret = dp[length][num];
if(ret!=-1)
return ret;
ret = 0;
if(num==0)
ret = func(1,length-1) % mod;
else if(num==9)
ret = func(8,length-1) % mod;
else
ret = (func(num+1,length-1) + func(num-1,length-1)) % mod;

return ret;
}

int main(void) {

cin>>N;
memset(dp,-1,sizeof(dp));

for(int i=0;i<=9;i++)
dp[1][i] = 1;

for(int i=1;i<=9;i++) {
ans += func(i, N);
ans = ans % mod;
}

cout<<ans % mod<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/10844/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.