山东省第五届ACM省赛题——Hearthstone II(第二类Stiring数)

题目描述
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

将n个队伍分配到m个桌子(?)上,抽象将n个元素分成m个集合的方法,要用到第二类斯特林数。因为m个桌子是不同的,所以结果应是m!*s(n,m)

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#define mod 1000000007
using namespace std;
long long s[110][110],ans;
void Init()
{
    s[1][1]=1;
    for(int i=2;i<=100;++i)
        for(int j=1;j<=i;++j)
        s[i][j]=(s[i-1][j-1]+j*s[i-1][j])%mod;
}
int main()
{
    Init();
    int n,m,i;
    while(~scanf("%d%d",&n,&m))
    {
        ans=1;
        for(i=1;i<=m;++i)
            ans=(ans*i)%mod;
        ans=(ans*s[n][m])%mod;
        printf("%lld\n",ans%mod);
    }
    return 0;
}

你可能感兴趣的:(Class,ACM,each)