Bzoj1426 Collecting Stamps

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.