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

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

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;   
}   
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值