HDU 4870 rating (probability DP)

Source: Internet
Author: User

Question Link

Question:

A girl plays a game. If the top 200 match results, she can add 50 points to her rating. Otherwise, she will score 100 points (the minimum rating value is 0, the maximum value is 1000 ---- the probability of being able to enter the first 200 is P ). In order to reach 1000 points, the girl used two accounts for the competition, each time using the account with low rating, until one account rating reached 1000. Given a P, the question is the expected value of the number of matches.

Analysis:

This question was originally a question of Gaussian elimination, but the idea of Gaussian elimination is a bit dizzy. After reading the blog of great god, you can use DP to do it,

The two accounts do not really want to do this, because one account must have 1000 points when it reaches 950, And the other account must have points.

Each time 50 points, reaching 1000 points, so we can think of each time 1 point, reaching 20 points

DP [I] --- expectation that the score I is raised to the score I + 1

Recursive Formula: DP [I] = p * 1 + (1-p) * (DP [I-2] + dp [I-1] + dp [I] + 1) // upon success, need one step; waste one chance at failure, and rise 3 times from I-2

DP [0] indicates the number of places we need to perform from 0 to 50. There are two scenarios:

1. success. The probability is P, and the expected value is 1 * P.

2. failure, probability 1-p, expected to be (1-p) * (1 + dp [0]) So DP [0] = 1 * P + (1-p) * (1 + dp [0]), after simplification, DP [0] = 1/P;

DP [1] represents our expectation from the number of 50-fields, divided into two situations: 1. Success, probability is P, expectation is 1 * P

2. Failure, probability 1-P, expected to be (1-p) * (1 + dp [0] + dp [1])

So DP [1] = 1 * P + (1-p) * (1 + dp [0] + dp [1])

I> 2, the DP [I] method is divided into two situations: 1. Success, probability is P, expectation is 1 * P

2. Failure, probability 1-p, expected to be (1-p) * (1 + dp [I-2] + dp [I-1] + dp [I])

So DP [1] = 1 * P + (1-p) * (1 + dp [0] + dp [1])

 

So we can use sum to record two expectations from 0 to 1950, and then subtract d [19], because the other account only reaches.

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algorithm> 7 #define LL __int64 8 const int maxn = 20+10; 9 using namespace std;10 11 int main()12 {13     double d[maxn], p, q, sum;14     int i;15     while(cin>>p)16     {17         sum = 0;18         q = 1-p;19         d[0] = 1.0/p;20         d[1] = (1.0+q*d[0])/(1.0-q);21         sum += (d[0]+d[1])*2;22         for(i = 2; i < 20; i++)23         {24             d[i] = (1.0+q*d[i-1]+q*d[i-2])/(1.0-q);25             sum += d[i]*2;26         }27         printf("%.6lf\n", sum-d[19]);28     }29     return 0;30 }

 

HDU 4870 rating (probability DP)

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.