题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495

题目大意:有N个盒子,里面都放着礼物,M个人依次去选择盒子,每人仅能选一次,如果里面有礼物则将礼物取出来,把空盒子放回原位,若没有礼物,则把空盒子放回原位。求礼物被拿走的个数的数学期望。

令 x[i] 代表第i个人拿到的礼物的个数,即值为0或1。

那么,N个人拿到的礼物的个数为 X = Sigma(X[i])。

因此 E[X] = E[Sigma(X[i])] = Sigma(E[X[i]])

其中,X[i]服从两点分布,即E[X[i]] = P(i)。

定义状态f[i]代表第i个人能够抓到礼物的概率,可以将样本空间划分为第i-1个人拿到了礼物和第i-1个人没拿到礼物。

因此有 P(i) = P(i|~i-1) + P(i|i-1) 即 f[i] = f[i-1]*(f[i-1]-1/n)+(1-f[i-1])*f[i-1]

化简得f[i] = f[i-1]*(1-1/n)。

进一步。。数学期望就可以用等比数列求和公式来做了。。。。。

有代码:

 ///#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <numeric>
#include <iterator>
#include <iostream>
#include <cstdlib>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <cctype>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ size()
#define ST begin()
#define ED end()
#define CLR clear()
#define ZERO(x) memset((x),0,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const double EPS = 1e-; const int MAX_N = +; double f[MAX_N];
int N,M; int main() {
while( ~scanf("%d%d",&N,&M) ) {
f[] = 1.0;
double ans = 1.0;
for( int i=;i<=M;i++ ){
f[i] = (1.0-f[i-])*f[i-] + f[i-]*( f[i-]-1.0/N );
ans += f[i];
}
printf("%.11f\n",ans);
}
return ;
}

[SGU495] Kids and Prizes (概率dp)的更多相关文章

  1. SGU-495 Kids and Prizes 概率DP

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:有n个盒子,每个盒子里面放了一个奖品,m个人轮流去选择盒子,如果盒子里面 ...

  2. sgu 495. Kids and Prizes (简单概率dp 正推求期望)

    题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...

  3. SGU 495 Kids and Prizes:期望dp / 概率dp / 推公式

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意: 有n个礼物盒,m个人. 最开始每个礼物盒中都有一个礼物. m个人依次随 ...

  4. SGU495Kids and Prizes(数学期望||概率DP||公式)

    495. Kids and Prizes Time limit per test: 0.25 second(s) Memory limit: 262144 kilobytes input: stand ...

  5. SGU495 概率DP

    Kids and Prizes ICPC (International Cardboard Producing Company) is in the business of producing car ...

  6. sgu495:概率dp / 推公式

    概率题..可以dp也可以推公式 抽象出来的题目大意: 有 n个小球,有放回的取m次  问 被取出来过的小球的个数的期望 dp维护两个状态 第 i 次取出的是 没有被取出来过的小球的 概率dp[i] 和 ...

  7. 概率dp专场

    专题链接 第一题--poj3744 Scout YYF I  链接 (简单题) 算是递推题 如果直接推的话 会TLE 会发现 在两个长距离陷阱中间 很长一部分都是重复的 我用 a表示到达i-2步的概率 ...

  8. [转]概率DP总结 by kuangbin

    概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...

  9. 概率DP求解例题

    1,逆推状态:山东省赛2013年I题 Problem I: The number of steps Description Mary stands in a strange maze, the maz ...

随机推荐

  1. 升级OpenSSh到 7.3p1

    1.开启 telnet 服务 Linux yum install -y telnet-server telnet /etc/xinet.d/telnet 中的yes 修改为no service xin ...

  2. Erlang Materials Outline

    Motivation 因The Erlang Run-Time System迟迟没有出版,不等了. 梳理一下学习Erlang过程中的学习笔记,以准备一个关于Erlang的small but tight ...

  3. li标签的点击范围

    <div class="login_menu_choose"> <ul class="cursor">                & ...

  4. TCP SYN扫描学习笔记

    1.TCP SYN包扫描主机状态的原理:tcp协议规定,当目标主机收到一个tcp syn 包时,若目标主机处于开放状态,会返回给源主机一个tcp ack 包(目的端口开放),或者向源主机发送一个tcp ...

  5. 【转】DBMS_STATS.GATHER_TABLE_STATS详解

    转自http://blog.itpub.net/26892340/viewspace-721935/ [作用] DBMS_STATS.GATHER_TABLE_STATS统计表,列,索引的统计信息(默 ...

  6. QT5学习过程的小问题集锦

    *** only available with -std=c++11 or -std=gnu++11 添加以下代码到*.pro文件. CONFIG += c++11 在 Qt creator 中设置 ...

  7. 使用canvas元素-art方法绘制圆弧

    最近在学习HTML5,发现canvas真的很棒,canvas元素是一种可供绘图的平面,我们用JavaScript对它进行配置和操作.我这里说一下arc方法绘制圆弧,顺便提一下涉及到的基础知识. 首先看 ...

  8. 收藏:Linux系统信息查看命令大全

    系统# uname -a               # 查看内核/操作系统/CPU信息# head -n 1 /etc/issue   # 查看操作系统版本# cat /proc/cpuinfo  ...

  9. 《C与指针》第十二章练习

    本章例程 //12.3 #include <stdio.h> #include <stdlib.h> typedef struct NODE{ struct NODE *lin ...

  10. Atom安装activate-power-mode插件(震动炫酷)

    1.下载安装Atom,地址:https://atom.io/ 2.下载安装activate-power-mode插件,地址:https://github.com/JoelBesada/activate ...