[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 ...
随机推荐
- 特殊字符转义&时间格式化&获取URL参数
/*特殊字符转义*/ function htmlspecialchars (str) { var str = str.toString().replace(/&/g, "&& ...
- 调用外部js文件测试
test <p><img id="img" onclick="javascript:var s=document.createElement('scri ...
- socket实现手机连接网络打印机打印pos单
打印的工具类: public class PrintLine { String TAG = "xxl"; static String PRINT_IP = "192. ...
- Angular2 CLI 快速开发
Angular2 CLI 快速开发 http://www.tuicool.com/articles/z6V3Ubz 解决npm 的 shasum check failed for错误(npm注册国内镜 ...
- 如何通过IP地址添加网络打印机
以惠普的HP LaserJet 8100 Series PCL6为例. 1.从开始菜单选择“打印机和传真”. 2.鼠标右键“添加打印机”,然后单击“下一步”,选择“连接到这台计算机的本地打印机”,注意 ...
- codeforces Expecting Trouble
link:http://codeforces.com/contest/345/problem/A 写完这道题目才发现这场比赛只能用Ada语言提交== 好吧,逗我玩呢 考的是数学期望公式,二项分布的期望 ...
- 如何在Mac OS系统下配置Java服务器开发环境
1.http://www.oracle.com/technetwork/Java/javase/downloads/index-jsp-138363.html 安装JDK(可通过java -versi ...
- [BCB] C++ BUILDER 绘图 随机生成图形
由于老师要求要实现一个填充算法,而每次填充都需要一个源图形[不规则],用mspaint自己画太麻烦,于是打算自己动手随机生成. 这里用的是 Polygen()函数,但是注意首尾相接,另外,为了保证规则 ...
- Ruby 方法
Ruby 方法 Ruby 方法与其他编程语言中的函数类似.Ruby 方法用于捆绑一个或多个重复的语句到一个单元中. 方法名应以小写字母开头.如果您以大写字母作为方法名的开头,Ruby 可能会把它当作常 ...
- OC 相关
1.OC runtime的理解[转载] http://www.csdn.net/article/2015-07-06/2825133-objective-c-runtime/1