2014山东省第五届ACM省赛 Hearthstone II

Problem D: Hearthstone II

Time Limit: 2 Sec   Memory Limit: 64 MB
Submit: 62   Solved: 37
[ Submit][ Status][ Web Board]

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

题意: n个竞赛要用到m张桌子,每张桌子至少被用一次,桌子不同,问一共有多少种安排方法

也就是把n个元素分到m个非空且不可区分的集合中去。第二类Stiring数   s(n,m)意思是把n个元素分到m个非空且不可区分的集合中去。本题集合(桌子)是可区分的,那么答案为 m! *s(n,m).


#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 102;
const int mod = 1e9 + 7;

ll s[maxn][maxn];
int n, m;

int main()
{
    memset(s, 0, sizeof(s));
    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;
        }
    }
    while (scanf("%d%d", &n, &m) != EOF){
        ll ans = s[n][m];
        for (int i = 2; i <= m; i++){
            ans = (ans * i) % mod;
        }
        printf("%d\n", ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值