题目大意

n个房间对应n把钥匙

每个房间的钥匙随机放在某个房间内,概率相同。

有K次炸门的机会,求能进入所有房间的概率

一号门不给你炸

分析

我们设\(key_i\)为第i间房里的钥匙是哪把

视作房间i向房间\(key_i\)连了一条有向边

这相当于n个点n条边,且每个点出度入度都为1

就是m个环,就是置换嘛

相当于第一类斯特林数\(\left [\begin{matrix} n\\ m \end{matrix}\right]\)

做法

一个环中炸掉一个门就可以开环中所有的门

问题转化为求环的数量\(\le k\)的方案数

由于1不能单独在一个环中(因为不能炸)

\[\sum\limits_{k=1}^n\left( \left [\begin{matrix} n\\ k \end{matrix}\right]-\left [\begin{matrix} n-1\\ k-1 \end{matrix}\right] \right)
\]

(1单独在一个环中则剩下n-1个点和k-1个环)

solution

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef double db;
const int M=23; int rd(){
int x=0;bool f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
for(;isdigit(c);c=getchar()) x=x*10+c-48;
return f?x:-x;
} int tcas;
int n,m;
LL lh[M][M];
LL fac[M]; void init(){
int i,j;
lh[0][0]=1;
for(i=1;i<=20;i++)
for(j=1;j<=i;j++)
lh[i][j]=(i-1)*lh[i-1][j]+lh[i-1][j-1];
for(fac[0]=1,i=1;i<=20;i++) fac[i]=fac[i-1]*i;
} int main(){ init(); int i;
tcas=rd();
while(tcas--){
n=rd(),m=rd();
LL ans=0;
for(i=1;i<=m;i++)
ans+=lh[n][i]-lh[n-1][i-1];
printf("%.4lf\n",(db)ans/fac[n]);
}
return 0;
}

hdu 3625 Examining the Rooms 轮换斯特林数的更多相关文章

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

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

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

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3625 n^2 求斯特林数就行.要减去的就是1号钥匙在1号房间的方案,即 s[ n-1 ][ m-1] . ...

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

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

  4. HDU 3625 Examining the Rooms【第一类斯特灵数】

    <题目链接> <转载于 >>> > 题目大意:有n个锁着的房间和对应n扇门的n把钥匙,每个房间内有一把钥匙.你可以破坏一扇门,取出其中的钥匙,然后用取出钥匙打 ...

  5. HDU 3625 Examining the Rooms:第一类stirling数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3625 题意: 有n个房间,每个房间里放着一把钥匙,对应能开1到n号房间的门. 除了1号门,你可以踹开任 ...

  6. hdu 4372 Count the Buildings 轮换斯特林数

    题目大意 n栋楼有n个不同的高度 现在限制从前面看有F个点,后面看有B个点 分析 最高那栋楼哪都可以看到 剩下的可以最高那栋楼前面分出F-1个组 后面分出B-1个组 每个组的权值定义为组内最高楼的高度 ...

  7. HDU 3625 Examining the Rooms

    题目大意:有n个房间,n!个钥匙,在房间中,最多可以破k扇门,然后得到其中的钥匙,去开其它的门,但是第一扇门不可以破开,求可以打开所有门的概率. 题解:首先,建立这样的一个模型,题目相当于给出一个图, ...

  8. HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)

    Machine scheduling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. HDU - 4625 JZPTREE(第二类斯特林数+树DP)

    https://vjudge.net/problem/HDU-4625 题意 给出一颗树,边权为1,对于每个结点u,求sigma(dist(u,v)^k). 分析 贴个官方题解 n^k并不好转移,于是 ...

随机推荐

  1. BCB:UTF8Encode、AnsiToUtf8

    UTF8Encode: Call Utf8Encode to convert a Unicode string to UTF-8. WS is the Unicode string to conver ...

  2. targetcli save error

    iscsi configuration unable to save python error “ValueError: 'Implict and Explict' is not in list” / ...

  3. 使用notepad++远程编辑Linux文档

    上一篇中,我写了如何使用使用ftp服务器实现很方便的通信,这一篇我分享一个使用notepad++的一个NPPFTP插件远程编辑Linux中的文档的小技巧. 首先要确保你的Linux的ftp服务已经打开 ...

  4. 11.使用while和for循环分别打印字符串s=’asdfer’中每个元素

    1).for循环 s = 'asdfer' for i in s: print(i) 2).while循环 s = 'asdfer' while 1: print(s[index]) index += ...

  5. Visual Studio Professional 2015 简体中文专业版 序列号

    Visual Studio Professional 2015 简体中文专业版 专业版激活密钥:HMGNV-WCYXV-X7G9W-YCX63-B98R2 Visual Studio Enterpri ...

  6. Java中的List接口特有的方法

    import java.util.ArrayList; import java.util.List; /* List接口中特有方法: 添加 add(int index, E element) addA ...

  7. MVCPager学习小记

    1.PageIndexParameterName怎么关联? 答:其实就是Action里面的pageindex参数 例子: @Html.Pager(Model, new PagerOptions { P ...

  8. attachEvent和addEventListener 的使用方法和区别

    attachEvent方法,为某一事件附加其它的处理事件.(不支持Mozilla系列)addEventListener方法 用于 Mozilla系列document.getElementById(&q ...

  9. PHP计算两个日期相差的年月日时分秒

    $start_time = '2017-09-06 15:12:20'; $end_time = '2018-09-08 10:20:45'; get_time($start_time,$end_ti ...

  10. 创建Django项目并将其部署在腾讯云上

    这段时间在做scrapy爬虫,对爬出来的数据基于Django做了统计与可视化,本想部署在腾讯云上玩玩,但是因为以前没有经验遇到了一些问题,在这里记录一下: 首先说下Django的创建与配置: 1. 创 ...