HDU 3625 第一类斯特林数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3625
题意:
n个房间,房间里面放着钥匙,允许破门而入k个,拿到房间里面的钥匙后可以打开对应的门,但是1号门不能破门而入,求这样检查完所有房间,概率是多少?
分析:
钥匙随机放到房间,全排列有n!;
n个房间,破k个门进入,就是第一类斯特林数S(n,k);
但是,第一个门不能破门而入,就是要减去S(n-1,k-1);
然后求和SUM = S(n,i) {1<=i<=k}
概率就是 SUM / N!
#include <bits/stdc++.h> using namespace std; long long fac[];
long long stir[][]; void init() {
fac[] = ;
for(int i=;i<;i++)
fac[i] = i*fac[i-]; memset(stir,,sizeof(stir));
stir[][] = ;
stir[][] = ; for(int i=;i<;i++) {
for(int j=;j<=i;j++)
stir[i][j] = stir[i-][j-] + (i-)*stir[i-][j];
} }
int main()
{
init();
int t;
scanf("%d",&t);
while(t--) {
int n,k;
scanf("%d%d",&n,&k); long long cnt = ;
for(int i=;i<=k;i++)
cnt+= stir[n][i] - stir[n-][i-]; printf("%.4lf\n",1.0*cnt/fac[n]); }
return ;
}
HDU 3625 第一类斯特林数的更多相关文章
- hdu 3265 第一类斯特林数
先和第二类做一个对比 第一类Stirling数是有正负的,其绝对值是包含n个元素的集合分作k个环排列的方法数目.递推公式为, S(n,0) = 0, S(1,1) = 1. S(n+1,k) = S( ...
- hdu 3625 第一类striling 数
/** 第一类Stirling数是有正负的,其绝对值是包含n个元素的集合分作k个环排列的方法数目. 递推公式为, S(n,0) = 0, S(1,1) = 1. S(n+1,k) = S(n,k-1) ...
- hdu 4372 第一类斯特林数
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...
- hdu 3625 Examining the Rooms —— 第一类斯特林数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3625 学习斯特林数:https://blog.csdn.net/qq_33229466/article/d ...
- [HDU 3625]Examining the Rooms (第一类斯特林数)
[HDU 3625]Examining the Rooms (第一类斯特林数) 题面 有n个房间,每个房间有一个钥匙,钥匙等概率的出现在n个房间内,每个房间中只会出现且仅出现一个钥匙.你能炸开门k次, ...
- 【HDU 4372】 Count the Buildings (第一类斯特林数)
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu 4372 Count the Buildings —— 思路+第一类斯特林数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4372 首先,最高的会被看见: 然后考虑剩下 \( x+y-2 \) 个被看见的,每个带了一群被它挡住的楼, ...
- HDU 4372 Count the Buildings——第一类斯特林数
题目大意:n幢楼,从左边能看见f幢楼,右边能看见b幢楼 楼高是1~n的排列. 问楼的可能情况 把握看到楼的本质! 最高的一定能看见! 计数问题要向组合数学或者dp靠拢.但是这个题询问又很多,难以dp ...
- 【组合数学:第一类斯特林数】【HDU3625】Examining the Rooms
Examining the Rooms Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- c++读取list.txt中每行的字符串以及写入二进制文件
#include <fstream> #include <fstream> string path = ""; FILE* fp = fopen(path. ...
- 获取window.location.href路径参数
GetQueryString(param) { //param为要获取的参数名 注:获取不到是为null var currentUrl = window.location.href; //获取当前链接 ...
- BNU 20860——Forwarding Emails——————【强连通图缩点+记忆化搜索】
Forwarding Emails Time Limit: 1000ms Memory Limit: 131072KB This problem will be judged on UVA. Orig ...
- input 标签和a标签实现超链接的区别
a 标签和 input 标签都可以做链接点击的.代码: ------------------------------------------------------------------------ ...
- 51nod 1245 Binomial Coefficients Revenge
Description C(M,N) = M! / N! / (M - N)! (组合数).给出M和质数p,求C(M,0), C(M,1)......C(M,M)这M + 1个数中,有多少数不是p的倍 ...
- Java线程中断的本质深入理解
Java的中断是一种协作机制.也就是说调用线程对象的interrupt方法并不一定就中断了正在运行的线程,它只是要求线程自己在合适的时机中断自己. 一.Java中断的现象 首先,看看Thread类里的 ...
- PHP file_put_contents() 函数
file_put_contents() 函数把一个字符串写入文件中. 与依次调用 fopen(),fwrite() 以及 fclose() 功能一样. 语法如下 file_put_contents(f ...
- $smarty->assign('','')查询结果发送给模板
$article = one("select * from article WHERE id = '$id'"); $smarty->assign('abc(随便定义)',' ...
- vue中子组件的拆分 父组件与子组件之间的传值
vue是组件式开发,尽量独立出子组件 prop():父组件传值给子组件 $emit():子组件传值给父组件 子组件中的设置: 使用bind <template> : default-che ...
- linux环境下安装jdk(本文示例是jdk1.6.0_45)
第一步:创建一个文件夹安装jdk(虽说地址一般自定义,但是为了方便查找请按照笔者建议目录 ):/usr/java 将jdk-6u45-linux-x64.bin文件放到 /usr/java 文件夹 ...