Pagini recente » Cod sursa (job #1915597) | Cod sursa (job #1049790) | Cod sursa (job #1581847) | Cod sursa (job #18517) | Cod sursa (job #2516420)
#include <iostream>
#include<cstdio>
using namespace std;
const int N=305;
int dp[N][N];
const int MOD=10007;
int mult(int a,int b){
return a*b%MOD;
}
int ad(int a,int b){
return (a+b)%MOD;
}
int main()
{
FILE*fin,*fout;
fin=fopen("permutari2.in","r");
fout=fopen("permutari2.out","w");
int n,k;
fscanf(fin,"%d%d",&n,&k);
int fact=1;
for(int i=1;i<=n;i++){
fact=mult(fact,i);
dp[i][1]=fact-1;
dp[i][i]=1;
for(int j=2;j<i;j++){
long long s=0;
for(int x=1;x<i;x++){
s+=dp[i-x][j-1]*dp[x][1];
}
s%=MOD;
dp[i][j]=s;
dp[i][1]-=dp[i][j];
if(dp[i][1]<0)
dp[i][1]+=MOD;
}
}
fprintf(fout,"%d",dp[n][k]);
return 0;
}