题目链接: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 第一类斯特林数的更多相关文章

  1. hdu 3265 第一类斯特林数

    先和第二类做一个对比 第一类Stirling数是有正负的,其绝对值是包含n个元素的集合分作k个环排列的方法数目.递推公式为, S(n,0) = 0, S(1,1) = 1. S(n+1,k) = S( ...

  2. hdu 3625 第一类striling 数

    /** 第一类Stirling数是有正负的,其绝对值是包含n个元素的集合分作k个环排列的方法数目. 递推公式为, S(n,0) = 0, S(1,1) = 1. S(n+1,k) = S(n,k-1) ...

  3. hdu 4372 第一类斯特林数

    #include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...

  4. hdu 3625 Examining the Rooms —— 第一类斯特林数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3625 学习斯特林数:https://blog.csdn.net/qq_33229466/article/d ...

  5. [HDU 3625]Examining the Rooms (第一类斯特林数)

    [HDU 3625]Examining the Rooms (第一类斯特林数) 题面 有n个房间,每个房间有一个钥匙,钥匙等概率的出现在n个房间内,每个房间中只会出现且仅出现一个钥匙.你能炸开门k次, ...

  6. 【HDU 4372】 Count the Buildings (第一类斯特林数)

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  7. hdu 4372 Count the Buildings —— 思路+第一类斯特林数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4372 首先,最高的会被看见: 然后考虑剩下 \( x+y-2 \) 个被看见的,每个带了一群被它挡住的楼, ...

  8. HDU 4372 Count the Buildings——第一类斯特林数

    题目大意:n幢楼,从左边能看见f幢楼,右边能看见b幢楼 楼高是1~n的排列. 问楼的可能情况 把握看到楼的本质! 最高的一定能看见! 计数问题要向组合数学或者dp靠拢.但是这个题询问又很多,难以dp ...

  9. 【组合数学:第一类斯特林数】【HDU3625】Examining the Rooms

    Examining the Rooms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. 小众软件:Windows 下优化软件推荐—— Dism++ | 强迫症晚期患者福音 - 少数派

    Windows 下优化软件推荐—— Dism++ | 强迫症晚期患者福音 - 少数派 https://sspai.com/post/41992 官方网站免费下载

  2. jsonProperty

    //说明:界面参数name需要为: employeeName,Json格式的话需要传入:employee_name @JsonProperty("employee_name") p ...

  3. 带标准IO带缓存区和非标准IO 遇到fork是的情况分析

    废话不多说 直接代码 #include<stdio.h> #include<sys/types.h> #include<unistd.h> #include< ...

  4. linux运维基础之系统挂载与etc文件下介绍

    1) 目录结构说明: windows:磁盘----分区---格式化--系统 linux:磁盘--分区--生成一个文件(磁盘分区) linux 中一切皆文件 ll -h 显示人类能看懂的 mount - ...

  5. python 爬虫系列08-同步斗图一波

    一波大图来袭 import requests from lxml import etree from urllib import request import os import re def par ...

  6. java中构造函数的特点

    构造函数的名字必须和类名完全相同,构造函数不能有 返回值,就是void 也不要写,构造函数不可以被子类继承 构造函数可以重载但是不可以被子类覆盖. 简单的例子 class A{ A(){ } A(in ...

  7. 025-quartz之spring部分配置模板

    版本一: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://w ...

  8. oracle中的exists理解

    select * from EB where exists (select * from BB where Code=EB.Code) 把select 外层表EB看成是循环的,把每一个值eb.code ...

  9. sql server 远程备份 bak 删除

    前言: 管理一个公司的一个服务器,最近有一些维护SQLserver数据库活弄,写下防止忘了. 因为公司采用SQL\Redis\MongoDB共用,SQL用来存储基础的结构\权限\等一些杂七杂八的东西. ...

  10. JQuery.iviewer

    from: http://test.dpetroff.ru/jquery.iviewer/test/# jquery.iviewer.js: /* * iviewer Widget for jQuer ...