Kids and prizes
Time limit:250 ms
Memory limit:262144kb
64bit Io format:% I64d & % i64usubmit status practice sgu 495 appoint description: System crawler)
Description
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
MWinners. There are
NPrizes 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 wowould 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
NAnd
M().
Output
The first and only line of the output file shoshould 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.
Sample Input
sample input |
sample output |
5 7 |
3.951424 |
sample input |
sample output |
4 3 |
2.3125
|
N prizes are packed in N boxes. m chooses one of them, and each person extracts one. If there is a prize, put it back, the people behind him continue to pick up the box. ask the expected number of boxes finally retrieved.
In addition, DP [I] indicates the probability that I will receive the prize. DP [1] = 1; if the I-1 gets the prize, the probability of I to get the prize is DP [I-1]-1/N, otherwise the probability of I to get the prize is DP [I-1]. the transfer equation is DP [I] = DP [I-1] * (DP [I-1]-1/n) + (1-dp [I-1]) * DP [I-1].,
/*************************************** * *********************************> File Name: t. CPP> author: acvcia> mail: [email protected]> created time: tuesday, October 21, 2014 ******************************** **************************************** /# include <iostream> # include <algorithm> # include <cstdio> # include <vector> # include <cstring> # include <map> # include <queue> # include <Stack> # include <string> # Inc Lude <cstdlib> # include <ctime> # include <set> # include <math. h> using namespace STD; typedef long ll; const int maxn = 1e5 + 10; # define rep (I, a, B) for (INT I = (); I <= (B); I ++) # define Pb push_backint N, M, F; double DP [maxn]; int main (INT argc, char const * argv []) {While (~ Scanf ("% d", & N, & M) {memset (DP, 0, sizeof DP); DP [1] = 1; double ans = 1; for (INT I = 2; I <= m; I ++) {DP [I] = DP [I-1] * (DP [I-1]-1.0/N) + (1-dp [I-1]) * DP [I-1]; ans + = DP [I];} printf ("%. 10f \ n ", ANS);} return 0 ;}
Probability DP sgu495