HDU 4870 Rating

dp[i]---分数i涨到分数i+1的期望

dp[0]=1/p //分数0时不会降

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

dp[i]=p*1+(1-p)*(dp[i-2]+dp[i-1]+dp[i]+1)    //成功时,需要一步;失败时,浪费一次机会,并且要从i-2涨3次

ans[i][j]表示2个号分数是i和j的期望。

当rating上升时,2个号的rating最多相差1

所以我们只需要维护ans[i][i]和ans[i][i-1]即可。

Rating

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 740    Accepted Submission(s): 469
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
 
#include<cstring>
#include<queue>
#include<cstdio>
#include<iostream>
using namespace std;
#define ll long long
#define ERR puts("=======here========");
#define prt(k) cout<<#k"="<<k<<" "
#include<algorithm>

double dp[44],ans[55][55];
double p;
int main()
{
    while(cin>>p)
    {
        dp[0]=1/p;
        dp[1]=1+(1-p)/p*(1+dp[0]);
        for(int i=2;i<=22;i++)
        {
            dp[i]=1+(1-p)/p*(dp[i-2]+dp[i-1]+1);
        }
        ans[0][0]=0; ans[1][0]=dp[0]; ans[1][1]=ans[1][0]+dp[0];
        for(int i=2;i<=20;i++)
        {
            ans[i][i-1]=ans[i-1][i-1]+dp[i-1];
            ans[i][i]=ans[i][i-1]+dp[i-1];
        }
        printf("%.6f\n",ans[20][19]);
    }
}



你可能感兴趣的:(数据结构,算法,数学,ACM,比赛)