zoukankan      html  css  js  c++  java
  • zoj 3288 Domination (可能dp)

    ///dp[i][j][k]代表i行j列件,并把一k的概率
    ///dp[i][j][k]一种常见的方法有四种传输
    ///1:dp[i-1][j][k-1]  可能 (n-(i-1))*j/(n*m-(k-1))
    ///2:dp[i][j-1][k-1]   概率为  i*(m-(j-1))/(n*m-(k-1))
    ///3:dp[i-1][j-1][k-1]  概率为 (n-(i-1))*(m-(j-1))/(n*m-(k-1))
    ///4:dp[i][j][k-1]  概率为 (i*j-(k-1))/(n*m-(k-1))
    # include <stdio.h>
    # include <algorithm>
    # include <string.h>
    # include <iostream>
    using namespace std;
    double  dp[55][55][2510];
    int main()
    {
        int n,m,t,i,j,k;
        double ans;
        while(~scanf("%d",&t))
        {
            while(t--)
            {
                scanf("%d%d",&n,&m);
                memset(dp,0,sizeof(dp));
                dp[0][0][0]=1;
                for(i=1; i<=n; i++)
                {
                    for(j=1; j<=m; j++)
                    {
                        for(k=1; k<=n*m; k++)
                        {
                            if(i==n&&j==m)
                                dp[i][j][k]=dp[i-1][j][k-1]*(n-(i-1))*j/(n*m-(k-1))+dp[i][j-1][k-1]*i*(m-(j-1))/(n*m-(k-1))+dp[i-1][j-1][k-1]*(n-(i-1))*(m-(j-1))/(n*m-(k-1));
                            else
                                dp[i][j][k]=dp[i-1][j][k-1]*(n-(i-1))*j/(n*m-(k-1))+dp[i][j-1][k-1]*i*(m-(j-1))/(n*m-(k-1))+dp[i-1][j-1][k-1]*(n-(i-1))*(m-(j-1))/(n*m-(k-1))+dp[i][j][k-1]*(i*j-(k-1))/(n*m-(k-1));
                        }
                    }
                }
                ans=0;
                for(i=1; i<=n*m; i++) ///求期望==概率乘天数的和集
                    ans+=dp[n][m][i]*i;
                printf("%.12lf
    ",ans);
    
            }
        }
        return 0;
    }
    

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    winform音频播放器(有声小说[凡人修仙传])
    c# 小小备忘录
    编程语言 : Java的动态Web解决方案泛谈
    服务器 : Apache Tomcat
    荐书 : 调试九法
    框架应用 : Spring MVC
    框架应用 : Spring
    数据库 : Mysql
    框架应用:Mybatis
    String对象的一些函数用法与心得
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4917340.html
Copyright © 2011-2022 走看看