Collecting stamps [probability]

Collecting stamps [probability]

Missing persons return to series 2333

Put a Luo Gu link

When the school year OI or solving the problem on bzoj, I was troubled for a long time only the probability of knowledge of high school.

Now I have learned a system overview, you canHanging hammerThis question is the!

Is desirable to set the number of \ (X-\) , the answer is \ (E (\ + X-X-FRAC ^ {2} {2}) = \ {FRAC EX + EX ^ 2} {2} \) , need calculation \ (EX \) and \ (EX ^ 2 \) .

Consider has k-1 different stamps, to buy k-th, is to have \ (\ frac {k-1 } {n} \) the probability of failure \ (\ frac {n-k + 1} {n} \ ) is the probability of success, is a geometric distribution, it can be seen \ (X-X_2 = X_1 + + ... + X_n, \ X_k \ SIM G (\ {n-FRAC-n-K +. 1 {}}) \) .

The geometric distribution \ (X-\ SIM G (P) \) , there are \ (EX = \ frac {1 } {p}, \ var (X) = \ frac {1-p} {p ^ 2} \)

所以,\[EX=E(\sum_{i=1}^n X_i) = \sum_{i=1}^n EX_i = n\sum_{i=1}^n \frac{1}{i}\]
\[ \begin{align*} EX^2 & = E(\sum X_i^2 + \sum_{i \neq j}X_i X_j) \\ &= \sum EX_i^2 + \sum_{i \neq j}E(X_i X_j)\\ &= \sum var(X_i)+(EX_i)^2 + \sum_{i \neq j}(EX_i)(E X_j)\\ &= \sum_{k=1}^n (\frac{2n^2}{k^2}-\frac{n}{k})+\sum_{i\neq j}\frac{n^2}{ij} \\ \end{align*} \]
(由于\(X_i, X_j, i\neq j​\)独立,所以\(E(X_iX_j)=(EX_i)(EX_j)​\)

Therefore, \ (2 ^ n-ANS = \ sum_. 1} ^ {n-I = \ sum_ {J} = I n-^ \ {} ij of FRAC. 1} {\) , done!

Code:

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n;
int main() {
    cin >> n;
    double ans = 0, t = 0;
    for(int i=1; i<=n; i++) {
        t += 1.0/i;
        ans += 1.0/i * t;
    }
    ans *= n*n;
    printf("%.2f", ans);
}

Guess you like

Origin www.cnblogs.com/candy99/p/11780075.html