Kids and Prizes

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.

The management of the company would like to know how many prizes will be given by the above process. It is assumed that each winner picks a box at random and that all boxes are equally likely to be picked. Compute the mathematical expectation of the number of prizes given (the certificates are not counted as prizes, of course).

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)
input:
5 7
4 3
output:
3.951424
2.3125
题意:

有n个奖品,m个人排队来选礼物,对于每个人,他打开的盒子,可能有礼物,也有可能已经被之前的人取走了,然后把盒子放回原处。为最后m个人取走礼物的期望。
思路:

排队取,第1个人取到1个,dp[1]=1;后面的人dp[i]=p取到礼物盒子+dp前面的取到礼物盒子=(n-dp[i-1])/n + dp[i-1];
 #include"bits/stdc++.h"

 #define db double
#define ll long long
#define vl vector<ll>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = ;
const db PI = acos(-1.0);
const db eps = 1e-;
const ll INF = 0x3fffffffffffffff;
int t;
db dp[N];
int n,m;
void cal()
{
dp[]=;
for(int i=;i<=m;i++) dp[i]=dp[i-]+(n-dp[i-])/n;
printf("%f\n",dp[m]);
}
int main()
{ while(scanf("%d%d",&n,&m)==){
cal();
}
return ;
}

最新文章

  1. 如果把带有html的标记的字符串从服务端传到页面上,需要对其进行编码。Ajax.JavaScriptStringEncode()
  2. case break结构与return的有关要点
  3. PHP字符串处理
  4. FFMpeg ver 20160213-git-588e2e3 滤镜中英文对照
  5. FZU Problem 2082 过路费 树链剖分
  6. DB2导出脚本,重新建立数据库
  7. JPA oneToMany 级联更新
  8. mysql基础 事务的认识和使用
  9. 《灰帽Python-黑客和逆向工程师的Python编程》学习记录
  10. Google Map Api 谷歌地图接口整理
  11. 反射-Reflect
  12. ViewPager的基本使用--可左右循环切换也可自动切换
  13. [LeetCode#263]Factorial Trailing Zeroes
  14. python的and与or剖析
  15. C++中string
  16. 【转载】Android 开发 命名规范
  17. redis的set类型!!!!
  18. 入门Spring ioc
  19. iptables 配置说明
  20. window 服务器的Tomcat 控制台日志保存到日志文件.

热门文章

  1. Win10 手工安装.netframework3.5
  2. Sharepoint 2013企业内容管理学习笔记终章
  3. 【起航计划 014】2015 起航计划 Android APIDemo的魔鬼步伐 13 App-&gt;Activity-&gt;Translucent 半透明Activity Theme.Translucent
  4. R.java文件无法自动生成的问题
  5. 如何领域驱动设计?-实践感悟&amp;总结分享
  6. 关于HTML5,最牛逼的10本书!
  7. ubuntu linux double tab
  8. MySQL数据库实验二:单表查询
  9. QR分解与最小二乘(转载自AndyJee)
  10. BestCoder Round #89 1002 Fxx and game