zoukankan      html  css  js  c++  java
  • LA 6972 Domination

    6972 Domination Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays chess with his friends. What’s more, he bought a large decorative chessboard with N rows and M columns. Every day after work, Edward will place a chess piece on a random empty cell. A few days later, he found the chessboard was dominated by the chess pieces. That means there is at least one chess piece in every row. Also, there is at least one chess piece in every column. “That’s interesting!” Edward said. He wants to know the expectation number of days to make an empty chessboard of N × M dominated. Please write a program to help him. Input There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case: There are only two integers N and M (1 ≤ N, M ≤ 50). Output For each test case, output the expectation number of days. Any solution with a relative or absolute error of at most 10−8 will be accepted. Sample Input 2 1 3 2 2 Sample Output 3.000000000000 2.666666666667

    题意:题意:
    给一个n*m的矩阵,每天随机的在未放棋子的格子上放一个棋子。求每行至少有一个棋子,每列至少有一个棋子的天数的期望
     (1 <= NM <= 50). 

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <map>
    #include <algorithm>
    #include <set>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long Ull;
    #define MM(a,b) memset(a,b,sizeof(a));
    #define SC  scanf
    #define CT continue
    const double eps = 1e-10;
    const int inf = 0x3f3f3f3f;
    const double pi=acos(-1);
    const int mod=100000000;
    
    double dp[55][55][2505];
    int main()
    {
        int cas,n,m;SC("%d",&cas);
        while(cas--){
            SC("%d%d",&n,&m);
            MM(dp,0);
            dp[0][0][0]=1;
            dp[1][1][1]=1;
            for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            for(int k=max(i,j);k<=i*j;k++){
                int t=n*m-(k-1);
                double p1=dp[i][j][k-1]*(i*j-(k-1))/t;
                double p2=dp[i-1][j][k-1]*(n-(i-1))*j/t;
                double p3=dp[i][j-1][k-1]*(m-(j-1))*i/t;
                double p4=dp[i-1][j-1][k-1]*(n-(i-1))*(m-(j-1))/t;
                dp[i][j][k]=p1+p2+p3+p4;
            }
            double ans=0;
            for(int i=max(n,m);i<=n*m;i++)
                ans+=i*(dp[n][m][i]-dp[n][m][i-1]);
            printf("%.12f
    ",ans);
        }
        return 0;
    }
    

      题解:

  • 相关阅读:
    浅析Go中的MPG模式(一)
    panic: assignment to entry in nil map
    Golang 新手可能会踩的 50 个坑
    小刘的go面试题
    go 单元测试整理
    go test 测试单个文件和测试单个函数
    mac pro锁屏后没有声音了怎么处理
    go json返回时间字符串处理time.Time类型
    php求一个字符串中不重复的最长子串
    业务订单号生成算法,每秒50W左右,不同机器保证不重复,包含日期可读性好
  • 原文地址:https://www.cnblogs.com/smilesundream/p/5939198.html
Copyright © 2011-2022 走看看