USACO Cow Pedigrees

Code

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
/*
ID: wcr19961
PROG: nocows
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;

typedef long long LL;
const int maxn = 210;
const int maxk = 110;
const int mod = 9901;
int dp[maxn][maxk];

int main() {
freopen("nocows.in", "r", stdin);
freopen("nocows.out", "w", stdout);
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= k; ++i) {
dp[1][i] = 1;
}
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= k; ++j) {
for (int l = 1; l <= i - 2; ++l) {
dp[i][j] = (dp[i][j] + dp[l][j - 1] * dp[i - l - 1][j - 1]) % mod;
}
}
}
printf("%d\n", ((dp[n][k] - dp[n][k - 1]) % mod + mod) % mod);
return 0;
}