zoj 3822 Domination(2014牡丹江区域赛D称号)
Domination
Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge
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
概率dp,i为第i天,j为有j行已经被覆盖。k为k列已经被覆盖。则每一个dp[i][j][k]都能够由上dp[i-1]推出。
代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
double dp[5000][55][55];
int main(){
int m,n;
int T;
scanf("%d",&T);
memset(dp, 0, sizeof(dp));
dp[0][0][0]=1; while (T--) {
scanf("%d %d",&m,&n);
for(int i=1;i<=m*n+1-min(m, n);++i){
for(int j=1;j<=i&&j<=m;++j){
for(int k=1;k<=i&&k<=n;++k){
if(j>m){
dp[i][j][k]=0;
continue;
}
if(k>n) {
dp[i][j][k]=0;
continue;
}
if(j!=m||k!=n)
dp[i][j][k]=dp[i-1][j-1][k-1]*(double)((m+1-j)*(n+1-k))/(double)(m*n-i+1)+dp[i-1][j-1][k]*(double)(k*(m+1-j))/(double)(m*n-i+1)+dp[i-1][j][k-1]*(double)(j*(n+1-k))/(double)(m*n-i+1)+dp[i-1][j][k]*(double)(j*k+1-i)/(double)(m*n-i+1);
else
dp[i][j][k]=dp[i-1][j-1][k-1]*(double)((m+1-j)*(n+1-k))/(double)(m*n-i+1)+dp[i-1][j-1][k]*(double)(k*(m+1-j))/(double)(m*n-i+1)+dp[i-1][j][k-1]*(double)(j*(n+1-k))/(double)(m*n-i+1);
}
}
}
double result=0;
for(int i=1;i<=m*n+1-min(m, n);++i){
result+=i*dp[i][m][n];
}
printf("%.12f\n",result);
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
zoj 3822 Domination(2014牡丹江区域赛D称号)的更多相关文章
- zoj 3822 Domination(2014牡丹江区域赛D题) (概率dp)
3799567 2014-10-14 10:13:59 Acce ...
- ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)
Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...
- ZOJ 3822 ( 2014牡丹江区域赛D题) (概率dp)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 题意:每天往n*m的棋盘上放一颗棋子,求多少天能将棋盘的每行每列都至少有 ...
- ZOJ 3827 Information Entropy (2014牡丹江区域赛)
题目链接:ZOJ 3827 Information Entropy 依据题目的公式算吧,那个极限是0 AC代码: #include <stdio.h> #include <strin ...
- zoj 3829 Known Notation(2014在牡丹江区域赛k称号)
Known Notation Time Limit: 2 Seconds Memory Limit: 131072 KB Do you know reverse Polish notatio ...
- ACM学习历程——ZOJ 3829 Known Notation (2014牡丹江区域赛K题)(策略,栈)
Description Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathema ...
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest(2014牡丹江区域赛)
The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 题目链接 没去现场.做的网络同步赛.感觉还能够,搞了6题 A:这是签到题,对于A堆除掉.假设没剩余 ...
- 2014 牡丹江区域赛 B D I
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358 The 2014 ACM-ICPC Asia Mudanj ...
- 2014牡丹江区域赛H(特里)ZOJ3826
Hierarchical Notation Time Limit: 2 Seconds Memory Limit: 131072 KB In Marjar University, stude ...
随机推荐
- 【免费】iPhone上最好用的短信群发软件: 高速短信4.1
免费的最新的联系人.群组.多人发送短信软件短信群发4.1已经出炉.欢迎下载! *归属地信息让你时时记着好友的地方,让陌生号码变得不陌生: *您能够选择最经常使用的联系人然后发送高速短信; *群联系人 ...
- HDU4452Running Rabbits(模拟)
HDU4452Running Rabbits(模拟) pid=4452" target="_blank" style="">题目链接 题目大意: ...
- 与众不同 windows phone (7) - Local Database(本地数据库)
原文:与众不同 windows phone (7) - Local Database(本地数据库) [索引页][源码下载] 与众不同 windows phone (7) - Local Databas ...
- 如何在Android Studio上使用Github
首先,登陆到Github上并创建一个新repository.在屏幕右上角,点击“+”标记,并且选择“New repository”. 现在完成这个表格以新建一个叫做testproject的新repos ...
- Android 编译时出现r cannot be resolved to a variable
问题:编译出现r cannot be resolved to a variable 原因:SDK的Tools没有安装 解决:在Android SDK Manager中安装Tools部分,包括如下4项, ...
- Wamp 访问本地站点慢 的解决办法
自从安装了64位的windows 8.1之后,电脑运行速度变快了,可是重新下载安装64位的WAMP,访问本地的WEB站点确是很慢,根本不像是在本地访问,经过在WAMP论坛上搜索,终于找到了解决办法,主 ...
- sqlHelper的增删改查
当一件事情被反复做了多次后.会想找一种办法来取代自己去做这个反复的动作. 敲代码也一样. 在程序中.对于反复的部分.假设是全然同样,那我们就会想着将其写成一个方法(过程.函数),放在一个具有权限的需求 ...
- VSTO学习笔记(一)VSTO概述
原文:VSTO学习笔记(一)VSTO概述 接触VSTO纯属偶然,前段时间因为忙于一个项目,在客户端Excel中制作一个插件,从远程服务器端(SharePoint Excel Services)上下载E ...
- python—webshell_醉清风xf_新浪博客
python—webshell_醉清风xf_新浪博客 python—webshell (2012-05-23 09:55:46) 转载▼
- IE, FireFox, Opera 浏览器支持CSS实现Alpha透明的方法 兼容问题
一:要解决的问题时:在ie6-ie11下兼容下面透明上传文件button的效果. 实现方式通过滤镜实现. 二:效果图例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3N ...