SGU 495. Kids and Prizes(概率dp)
来源:互联网 发布:移动通信 算法 招聘 编辑:程序博客网 时间:2024/05/22 12:10
题目大意:n个盒子里装有礼物,m个人随机选择礼物,选完之后空盒子放回问选中的礼物数的期望。
解题思路1:m个人是独立的。对于每个礼物不被人选中的概率为((n-1)/n)^m,那么不被选中的礼物数的期望就是 n*((n-1)/n)^m。所以答案就是 n-n*((n-1)/n)^m;
思路2:每个人选中的概率有两种情况决定:上一个人选中或者没选中,直接进行dp。
495. Kids and Prizes
Time limit per test: 0.25 second(s)
Memory limit: 262144 kilobytes
Memory limit: 262144 kilobytes
input: standard
output: standard
output: standard
ICPC (International Cardboard Producing Company) is in the business of producing cardboard boxes. Recently the company organized a contest for kids for the best design of a cardboard box and selected M winners. There are N prizes for the winners, each one carefully packed in a cardboard box (made by the ICPC, of course). The awarding process will be as follows:
- All the boxes with prizes will be stored in a separate room.
- The winners will enter the room, one at a time.
- Each winner selects one of the boxes.
- The selected box is opened by a representative of the organizing committee.
- If the box contains a prize, the winner takes it.
- If the box is empty (because the same box has already been selected by one or more previous winners), the winner will instead get a certificate printed on a sheet of excellent cardboard (made by ICPC, of course).
- Whether there is a prize or not, the box is re-sealed and returned to the room.
Input
The first and only line of the input file contains the values of N and M ().Output
The first and only line of the output file should contain a single real number: the expected number of prizes given out. The answer is accepted as correct if either the absolute or the relative error is less than or equal to 10-9.Example(s)
sample input
sample output
5 7
3.951424
sample input
sample output
4 3
2.3125
//第一种#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-7#define M 1000100#define LL __int64#define INF 0x3f3f3f3f#define PI 3.1415926535898const int maxn = 100010;using namespace std;double p[maxn];int main(){ double n, m; while(cin >>n>>m) { printf("%.10lf\n",n-(n*pow((n-1)/n, m))); } return 0;}
//第二种#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-7#define M 1000100#define LL __int64#define INF 0x3f3f3f3f#define PI 3.1415926535898const int maxn = 100010;using namespace std;double p[maxn];int main(){ int n, m; while(cin >>n>>m) { p[1] = 1; double P = 1.0/n; for(int i = 2; i <= m; i++) p[i] = (1-p[i-1])*p[i-1]+p[i-1]*(p[i-1]-P); double ans = 0; for(int i = 1; i <= m; i++) ans += p[i]; printf("%.10lf\n",ans); } return 0;}
0 0
- SGU 495. Kids and Prizes(概率dp)
- SGU 495 Kids and Prizes(概率dp)
- Sgu 495 Kids and Prizes (概率dp)
- sgu 495 Kids and Prizes 概率dp
- SGU 495 Kids and Prizes 概率dp
- SGU 495 Kids and Prizes(概率dp)
- [概率dp] sgu 495 Kids and Prizes
- SGU 495 Kids and Prizes (概率DP)
- SGU 495 Kids and Prizes (概率DP)
- SGU 495 Kids and Prizes (概率DP入门)
- SGU-495 Kids and Prizes(概率DP)
- SGU 495 Kids and Prizes (概率期望DP)
- SSU 495. Kids and Prizes(概率DP)
- SGU 495. Kids and Prizes
- sgu 495 Kids and Prizes 求概率
- SGU 495 Kids and Prizes 概率 二项分布
- SGU 495 Kids and Prizes(概率)
- Kids and Prizes(SGU495,概率DP)
- 用代码编辑色块
- 微软的可疑更新DhMachineSvc.exe
- C++ bubber sort
- 初探linux子系统集之led子系统(二)
- Eclipse常用快捷键使用
- SGU 495. Kids and Prizes(概率dp)
- Spring配置数据源的三种方式(dbcp,c3p0,jndi)
- Andoird 项目 国际化方案 以及实现
- Party at Hali-Bula - POJ 3342 树形dp
- 在Mac OS X 10.9.4 Mavericks编译boost 1.55,并在xcode中使用.
- 简单实用国产JQuery UI 框架 之 DWZ富客户端框架
- Ultra-QuickSort
- 寻找一个矩阵的鞍点
- 产品经理学习笔记 MRD