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

来源:互联网 发布:淘宝绣花针 编辑:程序博客网 时间:2024/05/16 17:39

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 2100 25

示例输出

6354076161

提示

 

来源

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;   }       

0 0
原创粉丝点击