SGU495 Kids and Prizes probability DP, expected Formula

Source: Internet
Author: User

SGU495 Kids and Prizes probability DP, expected Formula

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.