第二类斯特林(Stirling)数的简单介绍和计算(小球入盒)
2015-11-28 20:33
483 查看
1
组合数学中一个典型的问题是:把从1到n标号的n个球放到k个无区别的盒子里,要求每个盒子里至少有一个小球,问不同的放法数量。例如,如果用A、B、C、D分别表示4个球,要分成两组(即放入无区别的盒子里),其方法有7种:
{A,B},{C,D}
{A,C},{B,D}
{A,D},{B,C}
{A},{B,C,D}
{B},{A,C,D}
{C},{A,B,D}
{D},{A,B,C}
这个数量可以用第二类斯特林 (Stirling) 数来计算,表示为S(n,k),S(4,2)=7。第二类斯特林 (Stirling) 数也是计算机科学应用中很常见的公式。它有如下的递推公式:
整数参数n≥k≥0,且初始条件满足
式中
是Knuth推荐的第二类斯特林数的表
2 经常用于小球入盒问题,如下:(sdut2883)
3
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.
组合数学中一个典型的问题是:把从1到n标号的n个球放到k个无区别的盒子里,要求每个盒子里至少有一个小球,问不同的放法数量。例如,如果用A、B、C、D分别表示4个球,要分成两组(即放入无区别的盒子里),其方法有7种:
{A,B},{C,D}
{A,C},{B,D}
{A,D},{B,C}
{A},{B,C,D}
{B},{A,C,D}
{C},{A,B,D}
{D},{A,B,C}
这个数量可以用第二类斯特林 (Stirling) 数来计算,表示为S(n,k),S(4,2)=7。第二类斯特林 (Stirling) 数也是计算机科学应用中很常见的公式。它有如下的递推公式:
整数参数n≥k≥0,且初始条件满足
式中
是Knuth推荐的第二类斯特林数的表
2 经常用于小球入盒问题,如下:(sdut2883)
#include <iostream> #include <string.h> #include <math.h> using namespace std; long long int s[111][111]; int main() { int n,m; long long int mod=pow(10,9)+7; while(cin>>n>>m){ //long long int g=jiecheng(m)%mod; memset(s,0,sizeof(s)); s[0][0]=1; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ s[i][j]=((s[i-1][j-1]*(m-j+1))%mod+(j*s[i-1][j])%mod)%mod; } } cout<<s [m]<<endl; } } /************************************** Problem id : SDUT OJ 2883 User name : Result : Accepted Take Memory : 572K Take Time : 30MS Submit Time : 2016-03-11 **************************************/
3
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 manyways 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
相关文章推荐
- mysql(5.6.24)+Navicat Premium(11.1.13) 安装
- 118.Oracle数据库SQL开发之 PLSQL编程——过程
- CCS5.5里DSP工程建及Simulator模式配置
- [转][自己打脸]Node.JS——NodeJS引用路径的小问题
- html元素类型 块级元素、内联元素(又叫行内元素)和内联块级元素。
- 我眼中的互联网运营感观——运营是什么?
- 117.Oracle数据库SQL开发之 PLSQL编程——异常
- cpu控制器
- 大端和小端(网络字节序和主机字节序)
- 116.Oracle数据库SQL开发之 PLSQL编程——游标
- 关于WordPress中新增分类目录提示“无法向数据库中插入条目”的解决方法
- 管道命令
- C# 操作Excel
- 欢迎使用CSDN-markdown编辑器
- ios开放中UILabel自动适应大小
- bean的作用域
- 约瑟夫环解法***
- 博客迁移指南
- arp 地址解析协议
- PHP5中PDO的入门教程