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\n",ans);
}
return 0;
}

  题解:

LA 6972 Domination的更多相关文章

  1. leggere la nostra recensione del primo e del secondo

    La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...

  2. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  3. 2014牡丹江D Domination

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  4. Mac Pro 使用 ll、la、l等ls的别名命令

    在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...

  5. Linux中的动态库和静态库(.a/.la/.so/.o)

    Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...

  6. Mac OS使用ll、la、l等ls的别名命令

    在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...

  7. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  8. zoj3822 Domination(概率dp)

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  9. 获取在线人数 CNZZ 和 51.la

    string Cookies = string.Empty; /// <summary> /// 获取在线人数 (51.la统计器) /// </summary> /// &l ...

随机推荐

  1. C结构体与JavaBean转化

    1 概述 (1)项目开发过程可能涉及多种语言,而多种语言之间如何数据交换格式是多种多样的,比如说:Java和JavaScript可以用json,Java和C#可以用xml等等. (2)这里提供一种C与 ...

  2. Redission

    https://github.com/redisson/redisson/wiki/6.-%E5%88%86%E5%B8%83%E5%BC%8F%E5%AF%B9%E8%B1%A1#61-%E9%80 ...

  3. VS 之github

    VS 代码发布到TFS上 1. 登录  visualstudio.com. 进入 https://qgb.visualstudio.com Create Project 这里是相当于新建了一个文件夹 ...

  4. faceswap深度学习AI实现视频换脸详解

    给大家介绍最近超级火的黑科技应用deepfake,这是一个实现图片和视频换脸的app.前段时间神奇女侠加尔盖朵的脸被换到了爱情动作片上,233333.我们这里将会从github项目faceswap开始 ...

  5. 初学java2 认识面向对象 以及运算符 输入输出

    面向对象 面向对象是一种程序设计思路,在设计一个程序时不需要考虑内部如何实现,只需要想他要实现什么功能 就像在餐馆点菜一样,你不需要知道他应该怎么做,你只需要决定你要吃什么 面向对象三大特征 继承 封 ...

  6. python中的not的意思

    python中的not的意思 在python中,not是逻辑判断,用于布尔值true和false,not true是false,not false是true.以下是not的一些常见用法:(1)当表达式 ...

  7. 关于dataset

    举个栗子: <div id="cost" data-drink="coffee" data-food="sushi" data-mea ...

  8. SQL优化的总结和一些避免全盘扫描的注意事项

    1.应尽量避免在 where 子句中使用 != 或 <> 操作符,否则将引擎放弃使用索引而进行全表扫描. 2.应尽量避免在 where 子句中使用 or 来连接条件,如果一个字段有索引,一 ...

  9. shell 判断月末日期

    有一个需求,根据输入的时间段,在这个时间段中的是月末的日期执行脚本 解决如下: #!/bin/bashif [ -z $1 ]thenecho "请输入年月日8位开始日期"exit ...

  10. 安装CDH5.11.2集群

    master  192.168.1.30 saver1  192.168.1.40 saver2  192.168.1.50 首先,时间同步 然后,ssh互通 接下来开始: 1.安装MySQL5.6. ...