山东省第五届ACM大学生程序设计竞赛 Hearthstone II 组合数学 Stirling数

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

提示

 

来源

2014年山东省第五届ACM大学生程序设计竞赛

示例程序

 

Stirling数,又称斯特灵数,在组合数学中,Stirling数可指两类数,第一类是有正负的,其绝对值是包含n个元素的集合分作K个排列的方法数目。第二类Stirling数是把包含n个元素的集合划分为正好K个非空子集的方法数目。

本题描述即要求没个桌子最少要用一次即是第二类Stirling数 然后每次可以用任意个桌子 使用总方案数为 S[N][M]*M!

ACcode:

#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define maxn 105
#define ll long long
const ll mod=1e9+7;
using namespace std;
ll stirling[maxn][maxn];
void init(){
    memset(stirling,0,sizeof(stirling));
    stirling[1][1]=1;
    for(ll i=2;i<=maxn;++i)
        for(ll j=1;j<=i;++j)
            stirling[i][j]=(stirling[i-1][j-1]+j*stirling[i-1][j])%mod;
}
int main(){
    int a,b;init();
    while(~scanf("%d%d",&a,&b)){
       ll ans=stirling[a][b];
       for(int i=2;i<=b;++i)ans=(ans*i)%mod;
       cout<<ans<<'\12';
    }
    return 0;
}


你可能感兴趣的:(C++)