SGU495KidsandPrizes probability DP, expected Formula

Source: Internet
Author: User
After I first entered this question, I had no place to submit it. for the first time I did the SGU question, I had to submit n boxes on HUSTOJ, which contained gifts. m people, each person took them, after the gift is obtained, the box is put back. The expectation of choosing the number of gifts is assumed that the equation dp [I] is the probability that the first person will receive the gift, however, the state transition equation does not know what to do. after a long time, there is no solution. In fact, the boundary is dp [1].

Question

After this question is first entered, there is no place to submit it. The first SGU question can only be submitted on HUSTOJ.

There are n boxes in which there are gifts. m people, each person takes them. after they take the gift, they take it out and put it back, hoping to select the number of gifts.

In fact, at the beginning, we assume that the equation dp [I] is the probability that I would receive a gift for the person I, but the state transition equation does not know what to do, and there is no way to think about it for a long time,

In fact, the boundary is dp [1] = 1. the first person to be selected must be in the middle.

The next person is composed of two parts: dp [I] = (1-dp [I-1]) * dp [I-1] + ........., if the previous person is not selected, the probability of the selected one is the same as that of the previous one. if the previous person is selected, I really thought about it for a long time, but there is no idea, and there is no way at last. I read another blog, and the person used a formula to do it. but I think probability DP can be pushed. let's see his introduction, at the beginning, I emphasized that m's personal gift selection is an independent event. well, at this time, I was a bit confused. I 've been learning probability theory for a long time and forgot a bit, every time a gift is selected, the probability of people choosing a gift is reduced by 1/n. In this case, my understanding is that the first choice is to choose one from n, after a gift is missing, the probability of the selected gift is 1/n less. for example, if there are five gifts at the beginning, the probability of the first selection is 1, the second time I thought it would be 4/5. In fact, there are only four gifts left, but there is still one empty box, so the probability of a person being selected is 4/5. I have done more before, later, I thought it was 1/4. I forgot about the overall situation. the previous candidate took the gift and it didn't affect your choice this time, because you chose it in so many boxes, the selected range does not change, so the other part of the equation will come out.

Dp [I] = (1-dp [I-1]) * dp [I-1] + dp [I-1] * (dp [I-1]-1/n) // you may have doubts about this, n is bigger than m. if n is smaller than m, will it be negative?

It should be because I thought too much, and I had to get the gift later, so it would always be 0, even if the negative value is multiplied by 0, it would be the same.

In this way, the probability of each individual getting a gift is obtained. how can we find the expectation? Haha, I really don't know. I forgot the probability... my idea at the time was that everyone's probability was multiplied by 1 and then accumulated. I tried the case right. after I handed in the case, I went through it... Why is the pinch? no explanation is provided after reading other people's blogs... Baidu has an expectation of independent events for a while. I know n * p methods and found a two-item distribution calculation method. I forgot this, however, after a while, I found that I still had no contact with this question. please give an explanation of the giant passing by. it's too late. I will study it again tomorrow.


int n,m;double dp[100000 + 55];void init() {}bool input() {while(cin>>n>>m) {return false;}return true;}void cal() {dp[1] = 1.00;for(int i=2;i<=m;i++)dp[i] = dp[i - 1] * (dp[i - 1] - 1.00/n*1.0) + dp[i - 1] * (1 - dp[i - 1]);double ans = 0.00;for(int i=1;i<=m;i++)ans += dp[i] * 1.00;printf("%.10lf\n",ans);}void output() {}int main() {while(true) {init();if(input())return 0;cal();output();}return 0;}


Oh, after I finish the problem, I tried it again before I went there. well, I found that this is also possible, that is, I add one step to each step, the number of steps taken by the worker is the same as before. because dp [I] indicates the selected probability, it must be selected. Therefore, it is okay to add 1, then the equation of state 1 becomes. dp [I] represents the expectation of the number of gifts selected by the previous one until dp [m] is the answer, however, it is a problem for other directions. Isn't this m step? What is the relationship with the number of gifts? Actually, it's okay. if n is greater than m, you can choose at most m gifts. if n is less than m, then the probability will be zero. so you can add it like this, in the next step, the multiplication is changed to 0, which is messy. if you deny yourself, you will be sure of yourself again. haha, it's so annoying. go to bed...


int n,m;double dp[100000 + 55];void init() {}bool input() {while(cin>>n>>m) {return false;}return true;}void cal() {dp[1] = 1.00;for(int i=2;i<=m;i++)dp[i] = dp[i - 1] * (dp[i - 1] - 1.00/n*1.0) + dp[i - 1] * (1 - dp[i - 1]) + 1;//double ans = 0.00;//for(int i=1;i<=m;i++)//ans += dp[i] * 1.00;printf("%.10lf\n",dp[m]);}void output() {}int main() {while(true) {init();if(input())return 0;cal();output();}return 0;}



Then there is an interest in the formula, and an independent event is expected to have a kind of N * P. in turn, the probability of each gift being deselected is (n-1) /n, so the probability that n gifts will not be selected will not be mentioned.

N * (n-1)/n) ^ m is not selected for the last n gifts,

So the expectation for the selected gift is n-n * (n-1)/n) ^ m, haha, kneeling. it's better to think about it than to think about it for a long time, the simple probability expectation formula is solved.


int n,m;double dp[100000 + 55];void init() {}bool input() {while(cin>>n>>m) {return false;}return true;}void cal() {double ans = n * 1.00;double tmp = 1.00;for(int i=1;i<=m;i++) {tmp *= (n - 1)*1.0/n*1.0;}ans = ans - n * tmp;printf("%.10lf\n",ans);}void output() {}int main() {while(true) {init();if(input())return 0;cal();output();}return 0;}


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.