Title:
There are m people, n boxes, and each box initially contains a prize.
Each time, a person randomly draws one of the n boxes. If there is a prize in it, the prize is taken out; if not, it is put back intact.
Ask about the expectation of the number of prizes drawn.
Ideas:
At the beginning, when I think about people, I can't figure it out.
Each draw is independent. If you think about gifts, the probability of each gift being drawn is 1/n, and the probability of it not being drawn is (n-1)/n.
The probability that a gift is not drawn m times is ((n-1) / n) ^ m.
Then the expectation of the number left after n gifts are drawn m times is n * ((n-1) / n) ^ m, and the expectation of being drawn is also the expectation of the number obtained by the person is n - n * ((n-1)/n)^m.
Questions about probability should be thought more from the opposite side, thinking backwards, and thinking from different angles.
Code:
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 double qp(double k,int n) 6 { 7 if (n == 0) return 1.0; 8 double ans = qp(k,n / 2); 9 ans *= ans; 10 if (n&1) ans *= k; 11 return ans; 12 } 13 int main() 14 { 15 int n,m; 16 while (scanf("%d%d",&n,&m) != EOF) 17 { 18 double ans; 19 ans = 1.0 * n * (1.0 - qp(1.0 * (n-1)/n,m)); 20 printf("%.10f\n",ans); 21 } 22 return 0; 23 }