Hearthstone II[2014年山东省第五届ACM大学生程序设计竞赛] 第二类斯特林数

本文介绍了一个基于第二类斯特林数的算法,用于解决在限定条件下安排比赛使用牌组的问题,并给出了具体的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接
Problem 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

Source

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

解题思路:
1.第二类斯特林数,盒子不相同的模型

2.为什么要对1000000007取模

#include<bits/stdc++.h>
using namespace std;
//s[i][j]表示将i个球放入到j个相同的盒子里的方法数
long long int a,b,ans,s[105][105];
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]) % 1000000007;///竟然没看到有括号......
    return;
}
int main(){
    init();
    while(~scanf("%lld%lld",&a,&b)){
        ans = 1;
        for(int i = 1;i <= b;i++)
            ans = (ans * i) % 1000000007;
        ans = (ans * s[a][b]) % 1000000007;
        printf("%lld\n",ans);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值