Pagini recente » Cod sursa (job #2461116) | Cod sursa (job #374863) | Cod sursa (job #2232217) | Cod sursa (job #242120) | Cod sursa (job #2511505)
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e4+7;
const int N_MAX = 302;
int n, k;
int dp[N_MAX][N_MAX];
int main()
{
ifstream fin ("permutari2.in");
ofstream fout ("permutari2.out");
fin >> n >> k;
dp[0][0] = 1;
int fact = 1;
for(int i = 1; i <= n; i++)
{
fact = fact * i % MOD;
dp[i][1] = fact;
for(int j = 2; j <= i; j++)
{
for(int x = 1; x < i; x++)
dp[i][j] = (dp[i][j] + dp[i - x][j - 1] * dp[x][1]) % MOD;
dp[i][1] -= dp[i][j];
if(dp[i][1] < 0)
dp[i][1] += MOD;
}
}
fout << dp[n][k] << "\n";
return 0;
}