第二类斯特林(Stirling)数的简单介绍和计算(小球入盒)

1

组合数学中一个典型的问题是:把从1到n标号的n个球放到k个无区别的盒子里,要求每个盒子里至少有一个小球,问不同的放法数量。例如,如果用A、B、C、D分别表示4个球,要分成两组(即放入无区别的盒子里),其方法有7种:
{A,B},{C,D}
{A,C},{B,D}
{A,D},{B,C}
{A},{B,C,D}
{B},{A,C,D}
{C},{A,B,D}
{D},{A,B,C}

  这个数量可以用第二类斯特林 (Stirling) 数来计算,表示为S(n,k),S(4,2)=7。第二类斯特林 (Stirling) 数也是计算机科学应用中很常见的公式。它有如下的递推公式:
第二类斯特林(Stirling)数的简单介绍和计算(小球入盒)_第1张图片

整数参数n≥k≥0,且初始条件满足

式中是Knuth推荐的第二类斯特林数的表



2  经常用于小球入盒问题,如下:(sdut2883)

#include <iostream>
#include <string.h>
#include <math.h>

using namespace std;
long long int s[111][111];
int main()
{
    int n,m;
    long long int mod=pow(10,9)+7;
    while(cin>>n>>m){
        //long long int g=jiecheng(m)%mod;
        memset(s,0,sizeof(s));
        s[0][0]=1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                s[i][j]=((s[i-1][j-1]*(m-j+1))%mod+(j*s[i-1][j])%mod)%mod;
            }
        }
        cout<<s[n][m]<<endl;
    }
}
 



/**************************************
	Problem id	: SDUT OJ 2883 
	User name	:
	Result		: Accepted 
	Take Memory	: 572K 
	Take Time	: 30MS 
	Submit Time	: 2016-03-11
**************************************/



3

Hearthstone II

Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

The new season has begun, you have n competitions and m well prepared decks during the new season. Each competition you could use any deck you want, but each of the decks must be used at least once. Now you wonder how many ways are there to plan the season — to decide for each competition which deck you are going to used. The number can be very huge, mod it with 10^9 + 7.
 

输入

The input file contains several test cases, one line for each case contains two integer numbers n and m (1 ≤ m ≤ n ≤ 100).
 

输出

One line for each case, output one number — the number of ways.

示例输入

3 2
100 25

示例输出

6
354076161

你可能感兴趣的:(数学,ACM)