Pagini recente » Borderou de evaluare (job #3278045) | Cod sursa (job #2523187) | Cod sursa (job #2523324) | Cod sursa (job #3137927) | Cod sursa (job #2514223)
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
ifstream fin("permutari2.in");
ofstream fout("permutari2.out");
const int N = 305, MOD = 10007;
int dp[N][N];
int fact[N];
int main()
{
int n, k;
fin >> n >> k;
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i % MOD;
for (int i = 1; i <= n; ++i) {
dp[1][i] = fact[i];
for (int j = 1; j < i; ++j)
dp[1][i] = (dp[1][i] - dp[1][j] * fact[i - j] + MOD * MOD) % MOD;
}
dp[1][1] = 1;
for (int i = 1; i <= n; ++i)
for (int j = 2; j <= k && j <= i; ++j)
for (int k = 1; k <= i && j - 1 <= i - k; ++k)
dp[j][i] = (dp[j][i] + dp[1][k] * dp[j - 1][i - k]) % MOD;
fout << dp[k][n];
return 0;
}