[BOJ] 1328 고층 빌딩

Time Lapse :None

1328.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <memory.h>
#define MOD 1000000007
int dp[101][101][101];
long f(int n, int l, int r){
return (n==r&&l==1)||(n==l&&r==1) ? 1 : !n||!l||!r ? 0 : dp[n][l][r]!=-1 ? dp[n][l][r] : dp[n][l][r] = ((f(n-1,l,r)*(n-2))%MOD + f(n-1,l-1,r) + f(n-1,l,r-1)) % MOD;
}
int main() {
int N, L, R;
memset(dp,-1,sizeof(dp));
scanf("%d %d %d",&N, &L, &R);
printf("%d",f(N,L,R));
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/1328/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.