sdut 2883 Hearthstone II (第二类Stiring数)
来源:互联网 发布:传智播客 c语言笔记 编辑:程序博客网 时间:2024/06/05 15:26
Hearthstone IITime 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
提示
题意:
思路:第二类斯特灵数。
第二类Stirling数 S(p,k)
S(p,k)的一个组合学解释是:将p个物体划分成k个非空的不可辨别的(可以理解为盒子没有编号)集合的方法数。
k!S(p,k)是把p个人分进k间有差别(如:被标有房号)的房间(无空房)的方法数。
S(p,k)的递推公式是:S(p,k)=k*S(p-1,k)+S(p-1,k-1) ,1<= k<=p-1
边界条件:S(p,p)=1 ,p>=0 S(p,0)=0 ,p>=1
递推关系的说明:
考虑第p个物品,p可以单独构成一个非空集合,此时前p-1个物品构成k-1个非空的不可辨别的集合,方法数为S(p-1,k-1);
也可以前p-1种物品构成k个非空的不可辨别的集合,第p个物品放入任意一个中,这样有k*S(p-1,k)种方法。
#include <iostream>#include<cstdio>#include<string.h>const int mod=1e9+7;using namespace std;typedef long long LL;LL dp[101][101];LL mi[101];void init()///打表{ mi[0]=1; for(int i=1;i<=100;i++) mi[i]=mi[i-1]*i%mod; memset(dp,0,sizeof(dp)); // dp[1][1]=1; for(int p=1;p<=100;p++) { dp[p][0]=0; dp[p][p]=1; } for(int p=2; p<=100; p++) for(int k=1; k<=p-1; k++) { dp[p][k]=k*dp[p-1][k]+dp[p-1][k-1]; if(dp[p][k]>=mod) dp[p][k]%=mod; }}int main(){ init(); int n,m; while(scanf("%d%d",&n,&m)) { cout<<mi[m]*dp[n][m]%mod<<endl; } return 0;}
理解题意,弄懂第二类斯特灵数,直接打表即可
把p个物品放入k个非空有差别的房间中
S(P,K)=[ S(P-1,K-1)+S(P-1,K)*K ]*K!
0 0
- [ACM] SDUT 2883 Hearthstone II (第二类Stiring数)
- sdut 2883 Hearthstone II (第二类Stiring数)
- 山东省第五届ACM省赛题——Hearthstone II(第二类Stiring数)
- SDUT:2883 Hearthstone II(第二类Stirling数)
- 山东省第五届ACM大学生程序设计竞赛-Hearthstone II(组合数学-第二类Stirling数)
- SDUT 2883 Hearthstone II【打表找规律/Dp思维】
- 第一类stiring数
- 2014年山东省第五届ACM大学生程序设计竞赛--Hearthstone II(第一类Stirling数)
- 第五届山东省ACM Hearthstone II(Dp)
- 山东省第五届ACM大学生程序设计竞赛 Hearthstone II 组合数学 Stirling数
- 数日子(SDUT 2558)
- SDUT Fruit Ninja II (2416 积分)
- SDUT--枚举(删数问题)
- 2014山东省第五届ACM省赛 Hearthstone II
- 第五届ACM大学生程序设计竞赛:Hearthstone II
- 2014山东省第五届ACM省赛 Hearthstone II
- SDNU 1011(第二类stirling数)
- 第二类Stirling数
- 使用jbox做列表选择
- 用php和mysql开发招聘网站
- FrameBuffer
- VideoView 获取当前播放时间
- 高cpu排查
- sdut 2883 Hearthstone II (第二类Stiring数)
- 万物共享的物联网架构
- 研发管理总结
- 极光推送步骤(ios)
- MVC学习
- Java: JNI完全手册
- ..ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
- php Laravel 学习【composer安装】
- hiho 39 二分·归并排序之逆序对