[BOJ] 10160 암호

Time Lapse : None

10160.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<stdio.h>
int n,k;
long long dp[1000001];
int main(){
scanf("%d %d",&n,&k);
dp[0] = 1;
for(register int i = 1; i <= 5; ++i) dp[i] = dp[i-1]*k;
dp[5] = dp[4]*k - 2;
dp[6] = ((dp[5]-2)*k)%1000000009;
for(register int i = 7; i <= n; ++i){
dp[i] = (k*dp[i-1] - (dp[i-5]<<1) + dp[i-7])%1000000009;
if(dp[i]<0) dp[i]+=1000000009;
}
printf("%d",dp[n]);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/10160/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.