hdu 4870 Rating (概率dp)

http://acm.hdu.edu.cn/showproblem.php?pid=4870

Rating

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 433    Accepted Submission(s): 276
Special Judge


Problem Description
A little girl loves programming competition very much. Recently, she has found a new kind of programming competition named "TopTopTopCoder". Every user who has registered in "TopTopTopCoder" system will have a rating, and the initial value of rating equals to zero. After the user participates in the contest held by "TopTopTopCoder", her/his rating will be updated depending on her/his rank. Supposing that her/his current rating is X, if her/his rank is between on 1-200 after contest, her/his rating will be min(X+50,1000). Her/His rating will be max(X-100,0) otherwise. To reach 1000 points as soon as possible, this little girl registered two accounts. She uses the account with less rating in each contest. The possibility of her rank between on 1 - 200 is P for every contest. Can you tell her how many contests she needs to participate in to make one of her account ratings reach 1000 points?
 

Input
There are several test cases. Each test case is a single line containing a float number P (0.3 <= P <= 1.0). The meaning of P is described above.
 

Output
You should output a float number for each test case, indicating the expected count of contest she needs to participate in. This problem is special judged. The relative error less than 1e-5 will be accepted.
 

Sample Input
   
   
   
   
1.000000 0.814700
 

Sample Output
   
   
   
   
39.000000 82.181160
 

Author
FZU
 

Source
2014 Multi-University Training Contest 1
 

我还没有很理解这个dp,转载大神的解题报告,留着以后再来研究.
题目:一个女孩打比赛,每次比赛结果若在前200名则能给她的rating加上50分,否则将会将去100分(rating最小为0,最大为1000----能够进入前200的概率为p)。为了能够达到1000分,这个女孩使用两个帐号进行比赛,每次使用rating低的那个帐号比赛,直到有一个帐号rating达到1000。给定一个p,问最后需要进行比赛场数的期望值。


题解:首先我们想到的是推公式,以dp[i]代表从i*50-(i+1)*50的期望值。dp[0]和dp[1]需要单独处理。

            dp[0]代表我们从0-50需要进行的场数,分成两种情况:1.成功,概率为p,期望为1*p

                                                                                                              2.失败,概率1-p,期望为(1-p)*(1+dp[0])  

                                                                                                                -----所以dp[0]=1*p+(1-p)*(1+dp[0]) ,化简后dp[0]=1/p;

            dp[1]代表我们从50-100的场数期望,分成两种情况:1.成功,概率为p,期望为1*p

                                                                                                           2.失败,概率1-p,期望为(1-p)*(1+dp[0]+dp[1])   

                                                                                                                -----所以dp[1]=1*p+(1-p)*(1+dp[0]+dp[1]) ,化简后dp[1]=1+(1-p)/p*(1+dp[0]);

            i>2,dp[i]的求法,分成两种情况:1.成功,概率为p,期望为1*p

                                                                       2.失败,概率1-p,期望为(1-p)*(1+dp[i-2]+dp[i-1]+dp[i])   

                                                                        -----所以dp[1]=1*p+(1-p)*(1+dp[0]+dp[1]) ,化简后dp[1]=1+(1-p)/p*(1+dp[i-2]+dp[i-1]);

这样,因为要使用两个帐号进行比赛,所以我们最后到达的状态就是一个帐号rating=1000,另外一个=950,只需要进行dp求和就行了。


另外这题也能用高斯消元做,目前不会,正在学习

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<set>
#include<queue>
using namespace std;
#define nn 110000
typedef long long LL;
double p;
double dp[30];
int main()
{
    while(cin>>p)
    {
        double sum=0;
        dp[0]=1/p;
        dp[1]=1/(p*p);
        sum=dp[0]+dp[1];
        int i;
        for(i=2;i<=19;i++)
        {
            dp[i]=1+(1-p)/p*(1+dp[i-2]+dp[i-1]);
            sum+=dp[i];
        }
        printf("%.6lf\n",sum+sum-dp[19]);
    }
    return 0;
}

,等待补充。



你可能感兴趣的:(dp,动态规划,ACM)