山大工大联谊1007 combinatorial mathematics once more 【斯特灵数,贝尔数】
来源:互联网 发布:centos中文man手册 编辑:程序博客网 时间:2024/04/30 22:39
1007 combinatorial mathematics once more
description
如果你对组合数学有所涉猎,你一定会对组合划分非常熟悉,那么问题来了:现在给你一个数集S的大小n,请告诉我将它划分为集合的方法总数ans是多少?
input
多组数据输入,每组输入有一个n(n<=5000)
output
首先请输出Case #x,表示当前为第x个样例,然后输出ans的值,也许答案会很大,所以请输出ans%(1e9+7)
sample input
3
sample output
Case #1: 5
n=3,ans=5,
具体方法有如下几种:
{{a}, {b}, {c}}
{{a}, {b, c}}
{{b}, {a, c}}
{{c}, {a, b}}
{{a, b, c}}
Hints:
n=3,ans=5,
具体方法有如下几种:
{{a}, {b}, {c}}
{{a}, {b, c}}
{{b}, {a, c}}
{{c}, {a, b}}
{{a, b, c}}
题意: n个物品 可以都多少种不为空的划分。
分析: sigma(S(n,i)) i=1->n,其中S(n,i)为第二类斯特林数。亦或者B(i),其中B表示贝尔数。 详见代码后。
#include<iostream>#include<cstdio>#include<cstring>#include<ctime>#include<algorithm>#include <map>#include <queue>#include <set>using namespace std;//2015.3.29long long s[5000][5000];long long b[5000];int n;void Bell(int n){ for(int i=1;i<=n;i++) { s[i][0]=0; s[i][i]=1; b[i]=1; for(int j=i-1;j>=1;j--) { s[i][j]=(s[i-1][j-1]+j*(s[i-1][j]))%1000000007; } } for(int i=1;i<=5000;i++) { b[i]=0; for(int j=0;j<=i;j++) { b[i]=(b[i]+s[i][j])%1000000007; } }}int main(){ int q=1; Bell(5000); while(true) { cin>>n; printf("Case #%d:%I64d",q,b[n]); } return 0;}
HDU 2512 一卡通大冒险(斯特灵数,贝尔数)
转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526 by---cxlove
题目:将N张卡分成若干个集合,集合不为空,有多少种分法。
http://acm.hdu.edu.cn/showproblem.php?pid=2512
显然集合个数为1,2……n。也就是将N张卡放到i个集合内。
这类组合问题用第二类斯特灵数可以解决
S(P,K)=S(P-1,K-1)+K*S(P-1,K);表示P个元素放入K个不可区分的集合中而且集合不为空的划分个数。
那么问题的解为sigma(S(P,i)) (P=>i>=1) 这个和称为bell数。
Bell数是将P个元素集合分到非空且不可区分例子的划分个数。详见组合数学
- #include<iostream>
- #include<cmath>
- #include<cstdio>
- #include<cstring>
- #define LL long long
- #define eps 1e-7
- #define MOD 1000
- using namespace std;
- int stir2[2005][2005]={1};
- int bell[2005];
- int main(){
- for(int i=1;i<=2000;i++){
- stir2[i][0]=0;
- stir2[i][i]=1;
- for(int j=1;j<i;j++)
- stir2[i][j]=(stir2[i-1][j-1]+j*stir2[i-1][j])%MOD;
- }
- for(int i=1;i<=2000;i++){
- bell[i]=0;
- for(int j=0;j<=i;j++)
- bell[i]=(bell[i]+stir2[i][j])%MOD;
- }
- int n,t;
- cin>>t;
- while(t--){
- cin>>n;
- cout<<bell[n]<<endl;
- }
- return 0;
- }
0 0
- 山大工大联谊1007 combinatorial mathematics once more 【斯特灵数,贝尔数】
- 山大工大联谊1006 combinatorial mathematics
- 山大工大联谊1004 Count
- 山大工大联谊1003 A * B【坑】
- 山大工大联谊1005 count triangle【思维】
- 山大工大联谊1008 Integer Division I
- 山大工大联谊1009 integer division ii【DP】
- [SinGuLaRiTy-1004] Combinatorial Mathematics-Basic 组合数学
- 贝尔数
- 贝尔数&&斯特灵数&&调和数&&伯努利数
- hdu 2521 一卡通大冒险 (斯特灵数,贝尔数)
- HDU2512 一卡通大冒险【斯特灵数,贝尔数】
- yestoday once more
- Recommend DDD once more
- bug report once more
- Yesterday Once More
- Yesterday Once More
- Yesterday once more
- 拼接html字符串,onClick传递两个参数写法
- UIActivityIndicatorView 进度条(小菊花)-> 后面也可以自定义一个进度条
- redhat下安装gcc(转)
- Linux系统网络设备启动和禁止“ifconfig eth0 up/down”命令的跟踪
- android开发之数据库存取图片
- 山大工大联谊1007 combinatorial mathematics once more 【斯特灵数,贝尔数】
- uvalive 5052
- 第四周【项目1-三角形类的构造函数】(1)
- 编写一个函数,将一个数字字符串转换成该字符串对应的数字(包括正整数、负整数) 例如:“12“ 返回12 “-123“ 返回-123 函数原型:int my_atoi(char *str) {}
- Java基础-22
- 图 深度优先遍历 广度优先遍历 非递归遍历 图解算法过程
- WebMatrix3 启动报KeyNotFoundException错误解决方法
- css 常用属性索引
- c++初始化列表