当前位置: 首页 > 工具软件 > Moon Player > 使用案例 >

2018CCPC 吉林 DThe Moon[概率dp/记忆化搜索]

冯星阑
2023-12-01

The Moon
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 359 Accepted Submission(s): 160
Special Judge

Problem Description
The Moon card shows a large, full moon in the night’s sky, positioned between two large towers. The Moon is a symbol of intuition, dreams, and the unconscious. The light of the moon is dim, compared to the sun, and only vaguely illuminates the path to higher consciousness which winds between the two towers.

Random Six is a FPS game made by VBI(Various Bug Institution). There is a gift named “Beta Pack”. Mr. K wants to get a beta pack. Here is the rule.
Step 0. Let initial chance rate q = 2%.
Step 1. Player plays a round of the game with winning rate p.
Step 2. If the player wins, then will go to Step 3 else go to Step 4.
Step 3. Player gets a beta pack with probability q. If he doesn’t get it, let q = min(100%, q + 2%) and he will go to Step 1.
Step 4. Let q = min(100%, q + 1.5%) and goto Step 1.
Mr. K has winning rate p% , he wants to know what’s the expected number of rounds before he needs to play.

Input
The first line contains testcase number T (T ≤ 100). For each testcase the first line contains an integer p (1 ≤ p ≤ 100).

Output
For each testcase print Case i : and then print the answer in one line, with absolute or relative error not exceeding 106.

Sample Input
2
50
100

Sample Output
Case 1: 12.9933758002
Case 2: 8.5431270393

题意:1.起初物品掉落率q=2%;

2.玩家进行一次游戏,有p的概率获胜。

3.如果获胜了,有q的概率掉落一个叫Beta Pack的物品。如果掉落,游戏结束,否则q+=2%

4.如果不获胜,q+=1.5%。

重复2和3直到游戏结束。

求得到一个物品 进行游戏场次的期望。

题解:可以知道当q=100的时候百分百可以得到该物品,此时期望为1/p,这道题可以转化为已知某一状态的期望值,求初始状态的期望值,游戏结束的期望=1+本轮获胜但未掉落物品的概率 * 下一状态游戏结束的期望 + 本轮不获胜 * 下一状态游戏结束的期望 + 本轮游戏结束的概率 * 0(因为本轮已经结束了嘛,所以下一状态结束的期望为0)
可以有两种写法:
1、容易想到的是记忆化搜索的写法:

#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" is "<<x<<endl;
typedef long long ll;
const int maxn=1e5+5;
double dp[105][205];
double dfs(int p,int q){
    if(q==200)return 100.0/p;
    if(dp[p][q])return dp[p][q];
    double Q=(double)q/200;
    double P=(double)p/100;
    return dp[p][q]=1+P*(1-Q)*dfs(p,min(200,q+4))+(1-P)*dfs(p,min(200,q+3))+P*Q*0;
}
int main(){
    int t;
    int cas=0;
    scanf("%d",&t);
    while(t--){
        int p;
        scanf("%d",&p);
        for(int i=0;i<105;i++){
            for(int j=0;j<205;j++){
                dp[i][j]=0;
            }
        }
        printf("Case %d: %.7f\n",++cas,dfs(p,4));
    }

    return 0;
}

2、dp写法

#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" is "<<x<<endl;
typedef long long ll;
const int maxn=1e5+5;
double dp[205];
int main(){
    int t;
    int cas=0;
    scanf("%d",&t);
    while(t--){
        int p;
        scanf("%d",&p);
        for(int i=0;i<205;i++)dp[i]=0;
        dp[200]=100.0/p;
        for(int i=199;i>=4;i--){
            dp[i]=1+(1-0.01*p)*dp[min(200,i+3)]+(1-0.005*i)*0.01*p*dp[min(200,i+4)]+0.01*p*0.005*i*0;
        }
        printf("Case %d: %.7f\n",++cas,dp[4]);
    }
    return 0;
}

 类似资料: