Hearthstone II(第二类斯特灵数)

D - Hearthstone II
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
 use MathJax to parse formulas

Description

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.
 

Input

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

Output

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

Sample Input

3 2
100 25

Sample Output

6
354076161

Hint

 


这就是个简单的高中生数学问题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);
    }
}
(能力有限,可自行简化^_^)

猜你喜欢

转载自blog.csdn.net/qq_41232172/article/details/79702323
今日推荐