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 <= N, M <= 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的更多相关文章
- 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 ...
- 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 ...
- 2014牡丹江D Domination
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- Mac Pro 使用 ll、la、l等ls的别名命令
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...
- Linux中的动态库和静态库(.a/.la/.so/.o)
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...
- Mac OS使用ll、la、l等ls的别名命令
在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...
- .Uva&LA部分题目代码
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...
- zoj3822 Domination(概率dp)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- 获取在线人数 CNZZ 和 51.la
string Cookies = string.Empty; /// <summary> /// 获取在线人数 (51.la统计器) /// </summary> /// &l ...
随机推荐
- php7和PHP5对比的新特性和性能优化
1 抽象语法树( AST) 1)在 PHP5中,从 php 脚本到 opcodes 的执行的过程是: Lexing:词法扫描分析,将源文件转换成 token 流: Parsing:语法分析,在 ...
- springcloud注解
@EnableEurekaServer:启动一个服务注册中心提供给其他应用进行对话 @EnableZuulProxy:开启网关; @FeignClient:发现服务 @EnableFeignClien ...
- 集成第三方框架,报错NoSuchFieldError:logger
logger项目中使用springboot的版本是2.0.1.RELEASE,该版本依赖的spring版本为5.0.5.RELEASE (logger在spring版本5.0.7.RELEASE中), ...
- 【hash表】门票
问题 I: [哈希和哈希表]门票 题目描述 RPK要带MSH去一个更加神秘的地方!RPK带着MSH穿过广场,在第1618块砖上按下了一个按钮,在一面墙上随即出现了一个把手.RPK握住把手,打开了一扇石 ...
- hdu 6082 2017百度之星资格赛
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #inclu ...
- ORM框架之EntityFramework介绍
ORM框架之EntityFramework介绍 1. 简介 大家好!我是高堂. 作为一位伪前端程序猿,我给大家介绍一下微软的自家的 ORM框架. ADO.NET Entity Framework 以下 ...
- linux 打包与解压命令--常用
一般情况用这俩个就足以了 压缩 tar -czf jpg.tar.gz *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jp ...
- Centos7--从最小化系统发开发环境
Centos7--从最小化系统发开发环境 程序员总是离不开"环境"的困扰,从进入新手村的那一天就开始手动搞各种环境.虽然阿里云学生服务很方便,但是想弄集群真的买不起.正好实验室有 ...
- 10 TCP限流技术
TCP限流是因为让接收方充分接受完消息,保证数据安全,不会丢失 一.窗口机制介绍 发送端和接收端都拥有一个窗口,当发送端发送数据时,落进窗口的数据被发送,当接受端接受数据时,落进接收端窗口的数据将会被 ...
- mysql中binglog底层原理分析
binglog 是一个二进制的日志文件,会记录mysql的数据更新或潜在个跟新 (delete from table where id =xxx) 主从复制就是依靠binglog master -sl ...