[BOJ] 11051 이항 계수 2

Time Lapse :None

11051.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
#include <iostream>
#include <algorithm>
#include <memory.h>
#define mod 10007
using namespace std;
int dp[1001][1001];
int N,K;
int func(int n, int k)
{
if(n==k)
return 1;
if(k==0)
return 1;

int &ret = dp[n][k];
if(ret != -1)
return ret;

ret = (func(n-1,k-1)+func(n-1,k))%mod;

return ret;
}

int main(void) {
memset(dp,-1,sizeof(dp));
cin>>N>>K;
dp[1][0]=1;
cout<<func(N,K)<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/11051/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.