这就是个简单的高中生数学问题n个不同的球放入不同的盒子中;
如果可以有空的盒子那么结果就为:n^m;
如果不能有空的盒子:这就是个简单的第二类斯特灵数;
递推公式为:a(n,1)=a(n,n)=1;
a(n,m)=a(n-1,m-1)+m*a(n-1,m);
而且每个盒子也不同,最后把盒子以不同顺序排列,也就是乘m!。
AC代码:
#include <iostream>
#include<algorithm>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
long long int M=1e9+7, N=150,i,j,k,n,m,x,a[110][110],y,b[1100];
memset(a,0,sizeof(a));
a[1][1]=1;
for(i=2;i<110;i++)
for(j=1;j<i;j++)
a[i][j]=(a[i-1][j-1]+j*a[i-1][j])%M;
b[1]=1;
for ( i=2;i<101;i++)
{
b[i]=b[i-1]*i%M;
}
while(scanf("%lld%lld",&n,&m)!=EOF)
{
printf("%lld\n",((a[n+1][m]%M)*(b[m]%M))%M);
}
}
(能力有限,可自行简化^_^)