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 file 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
示例输出
6 354076161
提示
来源
2014年山东省第五届ACM大学生程序设计竞赛
题意:n次比赛,有m个场地,求每个场地至少用一次的方案数。
d[i][j]表示前i次比赛用了j个场地的方案数。
d[i][j] = d[i-1][j] * j + d[i-1][j-1] * (m-j+1)
include <string.h>
#include <cmath>
using namespace std;
#define mod 1000000007
long long int d[110][110];
int main()
{
int n,m;
while(cin>>n>>m)
{
memset(d,0,sizeof(d));
d[0][0]=1;
for(int i=1; i<=n; i++)
for(int j=1; j<=min(m,i); j++)
{
d[i][j]=(d[i-1][j]*j%mod+d[i-1][j-1]*(m-j+1)%mod)%mod;
}
cout<<d[n][m]<<endl;
}
return 0;
}

本博客探讨了在Hearthstone II赛季中如何合理规划赛程,确保每个比赛场地至少使用一次的策略,通过动态规划算法计算出方案数量,并提供了一段示例代码实现。
32万+

被折叠的 条评论
为什么被折叠?



