zoukankan      html  css  js  c++  java
  • CodeForces 148D Bag of mice

    概率,$dp$。

    $dp[i][j][0]$表示还剩下$i$个白猫,$j$个黑猫,公主出手的情况下到达目标状态的概率。

    $dp[i][j][1]$表示还剩下$i$个白猫,$j$个黑猫,龙出手的情况下到达目标状态的概率。

    一开始$dp[i][0][0]$均为$1$,答案为$dp[w][b][0]$。递推式很容易写:

    $dp[i][j][0]=i/(i+j)+j/(i+j)*dp[i][j-1][1]$

    $dp[i][j][1]=j/(i+j)*i/(i+j-1)*dp[i-1][j-1][0]+j*(j-1)/((i+j)*(i+j-1))*dp[i][j-2][0]$

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-6;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c = getchar();
        x = 0;
        while(!isdigit(c)) c = getchar();
        while(isdigit(c))
        {
            x = x * 10 + c - '0';
            c = getchar();
        }
    }
    
    double dp[1005][1005][2];
    int w,b;
    
    int main()
    {
        while(~scanf("%d%d",&w,&b))
        {
            memset(dp,0,sizeof dp);
            for(int i=1;i<=w;i++) dp[i][0][0]=1;
            for(int i=1;i<=w;i++)
            {
                for(int j=1;j<=b;j++)
                {
                    dp[i][j][0]=1.0*i/(i+j)+1.0*j/(i+j)*dp[i][j-1][1];
                    dp[i][j][1]=1.0*j/(i+j)*i/(i+j-1)*dp[i-1][j-1][0];
                    if(j>=2) dp[i][j][1]+=1.0*j*(j-1)/((i+j)*(i+j-1))*dp[i][j-2][0];
                }
            }
            printf("%.9f
    ",dp[w][b][0]);
        }
        return 0;
    }
  • 相关阅读:
    mycat 查询sql 报错
    mysql 主从 binlog
    数据库分库分表思路
    JavaScript数组知识
    JS判断当前页面是在 QQ客户端/微信客户端/iOS浏览器/Android浏览器/PC客户端
    js汉字转换为拼音
    工作中常用到的JS验证
    自动部署服务器代码
    php Excel 导入
    PHP 模拟http 请求
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6322921.html
Copyright © 2011-2022 走看看