Collecting stamps (mathematical expectation)

Source: Internet
Author: User

This problem is true fairy ...
You don't do it, qwq.
Konjac Konjac will only copy the QWQ
After copying the core feeling of guilt, had to write their own understanding + comments to send a blog to compensate for the QWQ
Hope to be able to pass the fairy ideas to other see this topic not very will do Dalao .....
--------------------------------------------------------------All this crap----------------------------------------------------- -------------------------
The expectation DP and the probability DP are different, generally are backwards pushes. (Dalao's experience)
As for why backward push, we can refer to other blogs on the internet, anyway I do not understand (too konjac). If there is any big guy will, can private messages I thank qwq.
--------------------------------------------------------------more than a crap----------------------------------------------------- --------------------------
All right, get to the chase.
The title asks for the expected amount of money to be spent on all stamps.
We set up a \ (g[i]\) array to represent the current collection of I stamps, to complete the collection of all kinds of stamps will also need to spend ,\ (f[i]\) array indicates the current collection of I stamps, The number of times it takes to collect all kinds of stamps then we think about how to rewind the DP from backwards forward.

We pull the state out, each state indicates that I now have a stamp, then we can clearly find the relationship between neighboring states: for the first state, it has the probability of \ (i/n\) selected stamps have been selected, then the state is unchanged, in addition, there is \ (( N-i)/n\ The probability of selecting a stamp that is not selected, it is transferred to the next state i+1.

Because Konjac konjac I am too konjac, originally did not how to do the desired problem, so I have some doubts about the inverted push, I would like to explain a little bit of recursion in the transfer of the amount of money each time, if the big guys understand that you don't have to look at the next section of the Qwq

Now we need to find the state transfer equation, considering how \ (g[i]\) transferred from \ (g[i+1]\) . But before we do that, we need to figure out one thing: The original title said, "The purchase of K-stamps to pay K yuan (that is, when the K-round pay k yuan, rather than the K-type postage stamps paid k yuan)", in order to facilitate understanding, we will be expected to have a total of P-wheel, then the weight of the push is definitely 1 to P of the series. But now we're pushing backwards, so now we're going to convert it to a distance to reach the goal and K-step time to pay K-yuan (that is, the number that is looking at p to 1), which is essentially the same. As for why it is possible to think of the f\ Array, it is to record the number of steps to get the amount of money that the round needs to pay.

The transfer of the \ (f\) array is relatively straightforward:
\[f[i]=f[i+1]\times \frac{n-i}{n}+f[i]\times \frac{i}{n}+1\]
Is the transfer mentioned earlier, and then because originally took the i+1 kind of stamps, now only I kind of stamps, so it is another step, so it is definitely to add the number of steps (last + 1)

\ (g\) array a bit fairy:
\[g[i]=g[i]\times \frac{i}{n}+g[i+1]\times \frac{n-i}{n}+\frac{i}{n}\times (f[i+1]+1) +\frac{n-i}{n}\times (f[i+1]+ 1) \]

The previous transfer is the same as the above idea, the following is to add to the transfer to their own + transfer to the next state of the and, +1 interpretation or the same as above QWQ

Here is the code: (Pay attention to the accuracy of the problem, you can open a long double comparison insurance)

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define MAXN 10010using namespace std;int n;long double f[MAXN],g[MAXN];int main(){    scanf("%d",&n);    for(int i=n-1;i>=0;i--) f[i]=f[i+1]+(long double)n/(n-i);    for(int i=n-1;i>=0;i--) g[i]=((long double)i/(n-i))*f[i]+g[i+1]+f[i+1]+((long double)n/(n-i));    printf("%.2lf\n",(double)g[0]);        return 0;}

Collecting stamps (mathematical expectation)

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.