# 题解 洛谷P4550/BZOJ1426 【收集邮票】

• 现在有$$\frac{i}{n}$$的几率会买到重复的邮票，即$$f[i] \times \frac{i}{n}$$.
• 现在有$$\frac{n-i}{n}$$的几率会买到新的邮票，即$$f[i+1] \times \frac{n-i}{n}$$.
• 花费$$1$$次买现在的邮票。

$$f[i] - f[i] \times \frac{i}{n} =f[i+1] \times \frac{n-i}{n} +1$$
$$f[i] \times \frac{n-i}{n} =f[i+1] \times \frac{n-i}{n} +1$$
$f[i] =f[i+1] \times \frac{n}{n-i}$

$g[i]=(f[i]+g[i]+1) \times \frac{i}{n} + (f[i+1]+g[i+1]+1) \times \frac{n-i}{n}$

$g[i]=\frac{i}{n}f[i]+\frac{i}{n}g[i] + \frac{n-i}{n}(f[i+1]+g[i+1]) +1 \frac{n-i}{n}g[i]=\frac{i}{n}f[i] + \frac{n-i}{n}(f[i+1]+g[i+1]) +1 g[i]=\frac{i}{n-i}f[i] + f[i+1]+g[i+1] +\frac{n}{n-i}$

$$g[n]$$仍然为0，我们还是可以倒推

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define RI register int
using namespace std;
const int N=1e4+2;
int n;double f[N],g[N];
inline double S(int x,int y){return (1.0*x)/(1.0*y);}
int main(){
scanf("%d",&n);
for(register int i=n-1;~i;--i){
f[i]=f[i+1]+S(n,n-i);
g[i]=S(i,n-i)*f[i]+g[i+1]+f[i+1]+S(n,n-i);
}printf("%.2lf",g[0]);
return 0;
}

posted @ 2019-01-15 19:41  babingbaboom  阅读(153)  评论(0编辑  收藏  举报