题目大意:有$n$个球,每一次取一个球然后放回,问期望多少次取遍所有球
题解:令$f_i$表示已经取了$i$种球,还要取的次数的期望。$f_i=\dfrac in(f_i+1)+\dfrac{n-i}n(f_{i+1}+1),f_n=0$
解个方程可得$f_i=\dfrac n{n-i}+f_{i+1}$,所有答案为$n\sum\limits_{i=1}^n\dfrac 1i$
卡点:无
C++ Code:
#include#define maxn 10000010const int mod = 20040313;#define mul(x, y) static_cast (x) * (y) % modinline void reduce(int &x) { x += x >> 31 & mod; }int n, ans;int inv[maxn];int main() { scanf("%d", &n); inv[0] = inv[1] = ans = 1; for (int i = 2; i <= n; ++i) { inv[i] = mul(mod - mod / i, inv[mod % i]); reduce(ans += inv[i] - mod); } printf("%lld\n", mul(ans, n)); return 0;}