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 ?le contains several test cases, one line for each case contains two integer numbers n and m (1?≤?m?≤?n?≤?100).
输出
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 ?le 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
100 25
示例输出
6
354076161
354076161
提示
来源
2014年山东省第五届ACM大学生程序设计竞赛
来源
2014年山东省第五届ACM大学生程序设计竞赛
题意:n场比赛,m个桌子可以用,每个桌子至少用一次,求有多少种分法。。。
思路:可以想象为将n个不同的球放入m个不同的盒子中,有多少种情况。。
先说一下第二类Stirling数:
s[n][m]: 将n个不同的球放入m个相同的盒子中得放法。
考虑第n个球的放法,
1、如果第n个球单独放在第m个盒中,有s[n-1][m-1]种放法。
2、如果前n-1个球放在m个盒中,则第n个球可以放在任意盒中,有s[n-1][m]*m种。
递推公式为:s[n][m]=s[n-1][m-1]+s[n-1][m]*m;
但本题中是m个不同的桌子,故最后结果为:m!*s[n][m];
以下AC代码:
#include<stdio.h>
#include<string.h>
long long mod=1e9+7;
int n,m;
long long s[105][105];
long long factoria(int n,int m)
{
long long ans=1;
for(int i=2;i<=m;i++)
{
ans*=i;
if(ans>=mod)
ans%=mod;
}
return ans;
}
void stirling()
{ ///打表
memset(s,0,sizeof(s));
s[1][1]=1;
for(int i=2;i<=104;i++)
for(int j=1;j<=i;j++)
{
s[i][j]=s[i-1][j-1]+j*s[i-1][j];
if(s[i][j]>=mod)
s[i][j]%=mod;
}
}
int main()
{
stirling();
while(~scanf("%d%d",&n,&m))
{
printf("%lld\n",factoria(n,m)*s[n][m]%mod);
}
return 0;
}