Hearthstone II
Time Limit: 2000MS
Memory Limit: 65536KB
Problem 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.
Example Input
3 2 100 25
Example Output
6 354076161
Hint
Author
2014年山东省第五届ACM大学生程序设计竞赛
题目大意:
给你N场比赛,有M张桌子,一场比赛选择一张桌子使用,需要保证N场比赛之后,所有的桌子都被这个队至少使用了一次。
问一共有多少种方案数 。
思路:
遇事不决先打表,打表找到规律:ans【i】【j】=j*(ans【i-1】【j】+ans【i-1】【j-1】)
Ac代码:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define LL long long int
int main()
{
LL ans[150][150];
memset(ans,0,sizeof(ans));
for(int i=1;i<=100;i++)
{
for(int j=1;j<=i;j++)
{
if(j==1)
{
ans[i][j]=1;
continue;
}
ans[i][j]=(ans[i-1][j]+ans[i-1][j-1])*j;
ans[i][j]%=mod;
}
}
int n,m;
while(~scanf("%d%d",&n,&m))
{
printf("%lld\n",ans[n][m]);
}
}