Cod sursa(job #465288)
#include <cassert>
#include <cstdio>
const int MOD = 10007;
const int MAX_N = 305;
int n, k;
int a[MAX_N][MAX_N];
int main() {
assert(freopen("permutari2.in", "r", stdin) != NULL);
assert(freopen("permutari2.out", "w", stdout) != NULL);
assert(scanf("%d %d", &n, &k) == 2);
assert(1 <= n && n <= 300);
assert(1 <= k && k <= n);
a[1][1] = 1;
for (int i = 2; i <= n; ++i)
a[i][1] = a[i - 1][1] * i % MOD;
for (int i = 2; i <= n; ++i) {
for (int j = 2; j <= i; ++j)
for (int k = 1; i - k >= j - 1; ++k)
a[i][j] = (a[i][j] + a[k][1] * a[i - k][j - 1]) % MOD;
for (int j = 2; j <= i; ++j)
a[i][1] = (a[i][1] - a[i][j] + MOD) % MOD;
}
printf("%d\n", a[n][k]);
}