第五届ACM大学生程序设计竞赛:Hearthstone II

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大学生程序设计竞赛
第二类斯特林数S(p,k)是将p个元素的集合划分成k个不可辨别的非空盒子的划分的个数.不可辨别唯一重要的任务在于各个盒子的内容是什么,而不是哪个盒子装了什么.
斯特林的公式如下:S(p,k)=k*S(p-1,k)+S(p-1,k-1).另外S(p,0)=0,S(p,p)=1,由此可推断出各个斯特林数的值.当盒子可辨别时,数目为k!*S(p,k),此题中相当于盒子可辩的,所以代码如下:
#include <iostream>
#include <cstring>
using namespace std;
const int  maxn=102;
long long s[maxn][maxn];
const long long mod=1e9+7;
void  inint()
{
    memset(s,0,sizeof(s));
    s[1][1]=1;
    for(int i=2; i<=maxn-1;i++)
    {
        for(int j=1;j<=i;j++)
        {
            s[i][j]=(s[i-1][j-1]+j*s[i-1][j])%mod;
        }
    }
}
int main()
{
     inint();
     int n,m;
     while(cin>>n>>m)
     {
           long long ans=1;
           for(int i=1;i<=m;i++)
           {
               ans=(ans*i)%mod;
           }
           cout<<ans*s[n][m]%mod<<endl;
     }
    return 0;
}

你可能感兴趣的:(第五届ACM大学生程序设计竞赛:Hearthstone II)