bzoj1426: 收集邮票(期望)

时间:2023-03-09 15:53:56
bzoj1426: 收集邮票(期望)

  推错半天式子T T

  设f[i]为买了i种卡,期望再买几张有n种卡

bzoj1426: 收集邮票(期望)

bzoj1426: 收集邮票(期望)

  设g[i]为买了i种卡,期望再花多少钱有n种卡

  可以把当前买卡的价格看作1,则以后买的所有卡片要增加1元,于是要加上f[i]和f[i+1]

bzoj1426: 收集邮票(期望)

bzoj1426: 收集邮票(期望)

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=,inf=1e9;
int n;
double f[maxn],g[maxn];
inline void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
int main()
{
read(n);
for(int i=n-;i>=;i--)f[i]=f[i+]+1.0*n/(n-i);
for(int i=n-;i>=;i--)g[i]=1.0*i/(n-i)*f[i]+g[i+]+f[i+]+1.0*n/(n-i);
printf("%.2lf",g[]);
}