Problem D: Hearthstone II
Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 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;
}