http://acm.hdu.edu.cn/showproblem.php?pid=4986

题意:n个钥匙放在n个箱子里,每个钥匙和箱子一一对应,求打开所有箱子的期望

题解:

题意:
求随机排列的期望循环个数。 分析: 【引理 1】对于一个随机排列的某个元素,处在一个长度为 k 的循环中的概率为 1/n(与循环的长度无关)。 证明:
方法一:
考察某个元素处在长度为 k 的循环中的方案数,有:
(n−1k−1)(k−1)!(n−k)!=(n−1)
C(k-1,n-1)(k-1)!(n-k)!=n-1

比上总的方案数得到概率。
(n−1)!n!=1n
(n-1)!/n!=1/n

方法二:
。。。
我们可以用第一题的方法,将每个排列写成 Cycle Notation,并将每个循环中最小的元素放在末尾。
那么每一个排列的 Cycle Notation 和另一个排列可以建立起一一对应。而 1 处在的循环中的长度等于它在排列中的位置,因此所有长度的概率都是 1n。 考虑 dp 。。设 e[n] 表示长度为 n 的排列的循环个数的期望。。我们枚举其中一个循环的长度。根据期望可加。。有。。。
e[n]=(Σi=1^n*e[n-i])/n
 e[n]=∑i=1ne[n−i]n
也就是 e[n] = H[n] (调和级数)
对于调和级数,可以较小项暴力,较大项时用 log() 近似。
调和级数的近似公式是ln(n+1)+r,r为欧拉常数,近似值是0.57721566490153286060651209
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std ; double dp[] ; int main()
{
dp[]=1.0 ;
for(int i= ;i<= ;i++)
dp[i]=dp[i-]+1.0/i ;
int n ;
while(~scanf("%d",&n))
{
if(n>)printf("%.4f\n",0.57721566490153286060651209+log(n+)) ;
else printf("%.4f\n",dp[n]) ;
}
return ;
}
 

HDU 4986的更多相关文章

  1. BestCoder7 1002 Little Pony and Alohomora Part I(hdu 4986) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4986 题目意思:有 n 个box(从左到右编号依次为1~n),每个box里面有一个随机的钥匙,有可能这 ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. Hive的Security配置

    为了更好地使用好Hive,我将<Programming Hive>的Security章节取出来,翻译了一下. Hive还是支持相当多的权限管理功能,满足一般数据仓库的使用. Hive由一个 ...

  2. Mysql多表关联删除操作

    直接看Sql即可: ;

  3. UTF-8

    UTF-8(8-bit Unicode Transformation Format)是一种针对Unicode的可变长度字符编码,又称万国码.由Ken Thompson于1992年创建.现在已经标准化为 ...

  4. ros科大讯飞语音识别环境配置

    以在线命令词识别为例: 链接:http://www.xfyun.cn/sdk/dispatcher 1.下载SDK,解压: 2.在ROS工作空间下创建一个Package: catkin_create_ ...

  5. 文件浏览器及数码相框 -2.3.1freetype_pc

    例子 #include <stdio.h> #include <string.h> #include <math.h> #include <ft2build. ...

  6. python 操作json

    认识 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - Dece ...

  7. Debugger Exception Notification

    --------------------------- Debugger Exception Notification --------------------------- Project PJSP ...

  8. [转]powerDesigner生成excel版本的数据库文件

    powerDesigner生成excel版本的数据库文件 出处:http://ray-allen.iteye.com/blog/1893347 脚本 excel  今天收到一个需求,要把数据库设计给一 ...

  9. 跨域SSO的实现

    翻译自CodeProject网站ASP.NET9月份最佳文章:Single Sign On (SSO) for cross-domain ASP.NET applications. 翻译不妥之处还望大 ...

  10. 从协议VersionedProtocol开始3——ClientProtocol、DatanodeProtocol、NamenodeProtocol、RefreshAuthorizationPolicyProtocol、RefreshUserMappingsProtocol

    1.ClientProtocol这个玩意的版本号是61L:DatanodeProtocol 是26L:NamenodeProtocol是 3L;RefreshAuthorizationPolicyPr ...