[BOJ] 1563 개근상

Time Lapse :6min 23sec

1563.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <memory.h>
#define MOD 1000000
int dp[1000][2][3];
int N;
int f(int d, int l, int a){
if(d==N) return 1;
if(dp[d][l][a]!=-1) return dp[d][l][a];
dp[d][l][a] = f(d+1,l,0);
if(!l) dp[d][l][a] += f(d+1,l+1,0);
if(a!=2) dp[d][l][a] += f(d+1,l,a+1);
dp[d][l][a] %= MOD;
return dp[d][l][a];
}
int main(void) {
scanf("%d",&N);
memset(dp,-1,sizeof(dp));
printf("%d",f(0,0,0));
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/1563/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.