[SGU495] Kids and Prizes (概率dp)
题目链接: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)的更多相关文章
- SGU-495 Kids and Prizes 概率DP
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:有n个盒子,每个盒子里面放了一个奖品,m个人轮流去选择盒子,如果盒子里面 ...
- sgu 495. Kids and Prizes (简单概率dp 正推求期望)
题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...
- SGU 495 Kids and Prizes:期望dp / 概率dp / 推公式
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=495 题意: 有n个礼物盒,m个人. 最开始每个礼物盒中都有一个礼物. m个人依次随 ...
- SGU495Kids and Prizes(数学期望||概率DP||公式)
495. Kids and Prizes Time limit per test: 0.25 second(s) Memory limit: 262144 kilobytes input: stand ...
- SGU495 概率DP
Kids and Prizes ICPC (International Cardboard Producing Company) is in the business of producing car ...
- sgu495:概率dp / 推公式
概率题..可以dp也可以推公式 抽象出来的题目大意: 有 n个小球,有放回的取m次 问 被取出来过的小球的个数的期望 dp维护两个状态 第 i 次取出的是 没有被取出来过的小球的 概率dp[i] 和 ...
- 概率dp专场
专题链接 第一题--poj3744 Scout YYF I 链接 (简单题) 算是递推题 如果直接推的话 会TLE 会发现 在两个长距离陷阱中间 很长一部分都是重复的 我用 a表示到达i-2步的概率 ...
- [转]概率DP总结 by kuangbin
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...
- 概率DP求解例题
1,逆推状态:山东省赛2013年I题 Problem I: The number of steps Description Mary stands in a strange maze, the maz ...
随机推荐
- 【转载】 Spark性能优化指南——基础篇
转自:http://tech.meituan.com/spark-tuning-basic.html?from=timeline 前言 开发调优 调优概述 原则一:避免创建重复的RDD 原则二:尽可能 ...
- CLR via C# 3rd - 07 - Constants and Fields
1. Constants A constant is a symbol that has a never-changing value. When defining a constant ...
- Ubuntu W: GPG error: http://archive.ubuntukey....NO_PUBKEY 8D5A09
在用 sudo apt-get update 时出现这样的报错: W: GPG error: http://archive.ubuntukylin.com:10006/ubuntukylin xeni ...
- java虚拟机判断对象是否存活的方式
引用计数算法: 给对象添加一个引用计数器,每当有地方应用时,计数器值就加一,当引用失效时,程序计数器就减一,只要引用计数器的值为零时,就表示对象不可能再被引用,例如微软的 component ob ...
- 记录一个UDP收包丢包的问题
这几天写GB28181平台接入层代码,对收到的PS包进行解包时,总是出现误码,最终导致rtsp点播服务中画面花屏. 分析了码流抓包数据之后,发现网络上没有丢包,遂认为PS流解包代码有bug,于是埋头分 ...
- 1.Counting DNA Nucleotides
Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...
- <a>标签的用法。
1.创建电子邮件链接: <html> <head> <title>发给朱永成</title> </head> <body> &l ...
- ueditor 上传的图片在内容里显示的尺寸过大的问题
没改动之前是上面这样的,图片显示不开,撑出了滚动条,想让他自适应100%,不出现滚动条 网上有方法 1.ueditor 的 themes 文件夹下有个iframe.css 加入以下代码,保存(原先的c ...
- 最小的N个和
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 有两个长度为 N 的序列 A 和 B,在 A 和 B 中各任取一个数可以得到 ...
- linux下根据进程名字获取PID,类似pidof(转)
linux有一个命令行工具叫做pidof,可以根据用户输入的进程名字查找到进程号,但有时候我们需要在程序里实现,不想调用system,在查阅了很多版本的pidof源代码后,没有发现一个自己感觉比较好的 ...