POJ 3088 斯特林
题意:有一个n个按钮的锁,按下一些按钮打开门,有多少开门方式,其中,一些按钮可以选,可以不选,选中的按钮 可以分成一些集合,集合之间无序,是同时按下的。
分析:
1、首先选择 i 个按钮,组合数
2、枚举分成的集合
3、i 个按钮分成无序集合,第二类斯特林数
4、集合之间有序,排列数
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring> using namespace std; const int maxn = ; long long fac[maxn];
long long C[maxn][maxn];
long long stir[maxn][maxn]; void init() { fac[] = fac[] = ;
for(int i=;i<maxn;i++)
fac[i] = fac[i-]*(long long)i; memset(C,,sizeof(C));
C[][] = ;
C[][] = C[][] = ; for(int i=;i<maxn;i++) {
C[i][] = C[i][i] = ;
for(int j=;j<i;j++)
C[i][j] = C[i-][j-] + C[i-][j];
} stir[][] = ;
for(int i=;i<maxn;i++)
for(int j=;j<=i;j++)
stir[i][j] = stir[i-][j-] + (long long)j*stir[i-][j]; } int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
init();
int kase = ;
while(t--) {
int n;
scanf("%d",&n); long long ans = ;
for(int i=;i<=n;i++) {
for(int j=;j<=i;j++) {
ans+=(C[n][i]*fac[j]*stir[i][j]);
}
} printf("%d %d %I64d\n",kase++,n,ans); }
return ;
}
POJ 3088 斯特林的更多相关文章
- POJ 3088
已知n,求n中取k(k<=n)个数组成的m(m<=n)个的集合的排列数. 于是,可以枚举选出k个数及枚举m个集合.这个很明显是二类斯特林数.而集合有序,则乘上m! #include < ...
- 【noi 2.6_9283】&【poj 3088】Push Botton Lock(DP--排列组合 Stirling数)
题意:N个编号为1~N的数,选任意个数分入任意个盒子内(盒子互不相同)的不同排列组合数. 解法:综合排列组合 Stirling(斯特林)数的知识进行DP.C[i][j]表示组合,从i个数中选j个数的方 ...
- POJ 1423 斯特林
题意:进制问题 分析: 打表,但是要用不能 long long 型,超内存. n! = log_{10}\sqrt{2{\pi}n}*(\frac{n}e)^n 精度要求 #include <c ...
- poj 1430 Binary Stirling Number 求斯特林数奇偶性 数形结合| 斯特林数奇偶性与组合数的关系+lucas定理 好题
题目大意 求子集斯特林数\(\left\{\begin{matrix}n\\m\end{matrix}\right\}\%2\) 方法1 数形结合 推荐一篇超棒的博客by Sdchr 就是根据斯特林的 ...
- POJ 1671 第二类斯特林数
思路: 递推出来斯特林数 求个和 if(i==j)f[i][j]=1; else f[i][j]=f[i-1][j-1]+f[i-1][j]*j; //By SiriusRen #include &l ...
- POJ 1430 Binary Stirling Numbers (第二类斯特林数、组合计数)
题目链接 http://poj.org/problem?id=1430 题解 qaq写了道水题-- 在模\(2\)意义下重写一下第二类Stirling数的递推式: \[S(n,m)=S(n-1,m-1 ...
- poj 1430 第二类斯特林数
1 #include <iostream> #include <cmath> #include <algorithm> using namespace std; i ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
随机推荐
- Knime读取Jason数据
Knime ETL 工具 Jason数据解析到DB 1. 下面例子是一段Jason代码 [{,,},{,,},{,,}] 2. 用文本文件存储上面代码. test_jason.txt 3. 用File ...
- windows 系统C盘暴增
系统: Windows Server 2012R2 问题: C盘200G的空间,暴增剩余3G.但是查看仅有69G的空间占用. 根源:Windows的虚拟文件,驱动器分页. 解决方案: 我的电脑-> ...
- malloc的可重入性和线程安全分析
malloc函数是一个我们经常使用的函数,如果不对会造成一些潜在的问题.下面就malloc函数的线程安全性和可重入性做一些分析. 我们知道一个函数要做到线程安全,需要解决多个线程调用函数时访问共享资源 ...
- (转) shell实例手册
shell实例手册 1文件{ touch file # 创建空白文件rm -rf 目录名 # 不提示删除非空目录(-r:递归删除 -f强制)dos2uni ...
- [TimesTen]TT7001: User authentication failed
在使用sqldeveloper连接TimesTen一直报[TimesTen][TimesTen 11.2.2.8.0 ODBC Driver][TimesTen]TT7001: User authen ...
- word 快捷键
Ctrl+shift+F9 清除word文档中的超链接
- cmd激活win10
自己动手,KMS激活win10 2016 长期服务版.步骤如下:命令提示符(管理员),依次输入以下3条命令 slmgr /ipk DCPHK-NFMTC-H88MJ-PFHPY-QJ4BJslmgr ...
- HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- Linux Kernel文件系统写I/O流程代码分析(一)
Linux Kernel文件系统写I/O流程代码分析(一) 在Linux VFS机制简析(二)这篇博客上介绍了struct address_space_operations里底层文件系统需要实现的操作 ...
- [转]C# - JSON详解
本文转自:http://www.cnblogs.com/QLJ1314/p/3862583.html 最近在做微信开发时用到了一些json的问题,就是把微信返回回来的一些json数据做一些处理,但是之 ...