Mathematical Methods:
- From each box to consider: After M-selection, at least once the probability of being selected. Because these boxes are independent of each other, the number of boxes selected is expected to be
1#include <iostream>2#include <cmath>3#include <cstdio>4 using namespacestd;5 6 intMain ()7 {8 intN, M;9 while(SCANF ("%d%d", &n, &m) = =2)Ten { One DoubleAns = n *1.0* (1.0-Pow ((1.0- (1.0/N)), (m)); Aprintf"%.12f\n", ans); - } - the return 0; -}
code June
Dp:
can also be considered from the person, set D (i) for the first person to win the probability of winning, then
If the i-1 person does not win the prize, then the first person to win and the first i-1 the probability of winning is the same;
If the i-1 individual wins, then the probability of the first person to win will be less than the probability of the first i-1 individual winning 1/n.
So d (i) = d (i-1) * (d (i-1)-1/n) + (1-d (i-1)) * d (i-1)
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 Const intmaxn=110000;8 DoubleDP[MAXN];9 intMain ()Ten { One Doublen,m; A while(SCANF ("%LF%LF", &n,&m) = =2) - { - Doublesum=1.0; thedp[1]=1; - for(intI=2; i<=m;i++) - { -Dp[i]= (1-dp[i-1]) *dp[i-1]+dp[i-1]* (dp[i-1]-1.0/n); +sum+=Dp[i]; - } +printf"%.9f\n", sum); A } at return 0; -}
code June
SGU 495 Kids and prizes