Time limit:1 Sec Memory limit:162 MB
submit:292 solved:232 Description has n different stamps, and Pip wants to collect all kinds of stamps. The only collection method is to the classmate said there to buy, each time can only buy one, and buy the postage stamp is the n kinds of stamps which is equal probability, the probability is 1/n. But because said also likes stamps very much, so leather buys the K stamps to pay K yuan money. Now that Del Piero has no stamps, Pip wants to know how much money he expects to get for all kinds of stamps. Input line, a number N n<=10000output how much money to pay. Keep two decimal places sample Input3Sample Output21.25
Expected recursion
When it comes to expectations, it looks like a super-Test IQ.
Recommended: http://blog.csdn.net/braketbn/article/details/51024591
Pushed for a long time, stuck in the last two-dimensional one-dimensional that step did not see ... Stupid cry
Although the code is very short, I like
1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7 using namespacestd;8 Const intmxn=10010;9 DoubleF[MXN],G[MXN];Ten intN; One intMain () { A inti,j; -scanf"%d",&n); -g[n]=f[n]=0; the for(i=n-1; i>=0; i--) g[i]=g[i+1]+n/(Double) (ni); - for(i=n-1; i>=0; i--) f[i]= (g[i]*i+n+ (f[i+1]+g[i+1]) * (n-i))/(Double) (ni); -printf"%.2f\n", f[0]); - return 0; +}
Bzoj1426 Collecting Stamps