题意有点难懂,其实就是让你从1-n中选r个数的间隔不小于k,然后她们的放在m个不区分的盒子里的数量。
第一步,有多少数可以选,我们先选(r-1)个间隔为k的,之后的可以任意选了,
所以为n-(r-1)*k+r-1,然后在这些数中选r个。
第二步,是第二类striling数,将p元素划分到k个不可区分的盒子,让k从1到m,求和即可
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define LL long long
#define inf 1000000007
const int maxn = 1005;
LL s[maxn][maxn];
LL ni(LL b,LL n)
{
LL x=1;
while(n)
{
if(n&1) x=(x*b)%inf;
b=(b*b)%inf;
n>>=1;
}
return x%inf;
}
LL Cm(LL n,LL m)
{
if(m>n) return 0;
else if(m==n) return 1;
if(m>n/2) m=n-m;
LL a=1,b=1;
for(int i=0;i<m;i++)
{
a=(a*(n-i))%inf;
b=(b*(i+1))%inf;
}
return (a*ni(b,inf-2))%inf;
}
int main()
{
s[0][0]=1;s[1][1]=1;
for(int i=1;i<=maxn;i++)
for(int j=1;j<=i;j++)
s[i][j]=(j*s[i-1][j]+s[i-1][j-1])%inf;
int n,r,k,m;
while(scanf("%d %d %d %d",&n,&r,&k,&m)!=EOF)
{
LL b=n-k*(r-1)+r-1;
LL a=0;
if(b<0) b=0;
b=Cm(b,r);
for(int i=1;i<=m;i++)
{
a=(a+s[r][i])%inf;
}
printf("%I64d\n",(a*b)%inf);
}
return 0;
}