2014牡丹江D Domination
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,还是比较简单,模拟比赛的时候没认真想,之后推了一下公式,还是比较容易想的。
三维,dp[i][j][k]表示已经占满i行j列,放了k个棋子,还需要放几个棋子到达条件的期望。
则:
dp[i][j][k]=(i*j-k)*1.0/(m*n-k)*dp[i][j][k+1]
+(m*j-i*j)*1.0/(m*n-k)*dp[i+1][j][k+1]
+(n*i-i*j)*1.0/(m*n-k)*dp[i][j+1][k+1]
+(m*n-m*j-n*i+i*j)*1.0/(m*n-k)*dp[i+1][j+1][k+1]+1;
从后向前递推即可;
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstring>
#define M(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f using namespace std; const int MAXN=;
double dp[MAXN][MAXN][MAXN*MAXN]; int main()
{
int m,n,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
for(int i = max(m,n);i<=m*n;i++)
dp[m][n][i]=;
for(int i=m;i>=;i--)
for(int j=n;j>=;j--)
{
if(i==m&&j==n)continue;
for(int k = i*j;k>=max(i,j);k--)
{
dp[i][j][k]=(i*j-k)*1.0/(m*n-k)*dp[i][j][k+]
+(m*j-i*j)*1.0/(m*n-k)*dp[i+][j][k+]
+(n*i-i*j)*1.0/(m*n-k)*dp[i][j+][k+]
+(m*n-m*j-n*i+i*j)*1.0/(m*n-k)*dp[i+][j+][k+]+;
}
}
//cout<<dp[3][30][90]<<endl;
printf("%.12lf\n",dp[][][]);
}
return ;
}
2014牡丹江D Domination的更多相关文章
- zoj 3822 Domination(2014牡丹江区域赛D称号)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- zoj 3822 Domination(2014牡丹江区域赛D题) (概率dp)
3799567 2014-10-14 10:13:59 Acce ...
- zoj 3822 Domination 概率dp 2014牡丹江站D题
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- 2014牡丹江——Domination
题目链接 题意: 给一个n*m的矩阵,每天随机的在未放棋子的格子上放一个棋子.求每行至少有一个棋子,每列至少有一个棋子的天数的期望 (1 <= N, M <= 50). 分析: 比較明显 ...
- ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)
Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...
- 2014 牡丹江区域赛 B D I
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358 The 2014 ACM-ICPC Asia Mudanj ...
- ZOJ 3829 Known Notation (2014牡丹江H称号)
主题链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5383 Known Notation Time Limit: 2 S ...
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest(2014牡丹江区域赛)
The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 题目链接 没去现场.做的网络同步赛.感觉还能够,搞了6题 A:这是签到题,对于A堆除掉.假设没剩余 ...
- zoj 3820(2014牡丹江现场赛B题)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5374 思路:题目的意思是求树上的两点,使得树上其余的点到其中一个点的 ...
随机推荐
- 强大的windbg定位内存泄露,两句命令搞定!
1.简单配置在windbg程序目录下有个gflags.exe,运行后设置: 运行CMD.EXE,输入"D:\Debugging Tools for Windows (x86)\gflags. ...
- Build to win!——获得小黄衫的感想
UPDATE: 应栋哥要求,上传了无遮挡的正面照(我的内心其实是拒绝的!(ㄒoㄒ)) 一.前言&背景 从大一上C++课程开始,栋哥就开始安利他大三的软工实践课. 时间过得飞快,大学转眼就过去一 ...
- ThreadPoolExecutor机制
一.概述 1.ThreadPoolExecutor作为java.util.concurrent包对外提供基础实现,以内部线程池的形式对外提供管理任务执行,线程调度,线程池管理等等服务: 2.Execu ...
- Linux Shell 从入门到删除根目录跑路指南
1.变量为空导致误删文件base_path=/usr/sbintmp_file=`cmd_invalid`# rm -rf $base_path/$tmp_file这种情况下如果 cmd 执行出错或者 ...
- Js里面的强制类型转换
js 和 PHP语言一样是弱类型语言.近期我也在看C语言,并没有传说中那么难,既是书中一再强调的指针部分,也没有那么夸张.至少是理论和语法理解起来不是很难.看起来凡是什么东西,不要总是被别人的话迷惑了 ...
- Wavefront OBJ 转换成OpenGL ES使用的C/C++文件
项目需要展示3D max模型,通过调研
- SSH(Struts Spring Hibernate开发框架)
Spring(Model) Spring的核心思想是IoC和AOP,Spring使得管理对象更加方便,极大的降低组件之间的耦合度,实现了软件各层之间的解耦. Struts(View) 使用Struts ...
- BZOJ2208: [Jsoi2010]连通数
tarjan缩点后拓扑排序,每一个点用一个bitset记录哪些点能到达它. PS:数据太水,暴力能过. #include<bits/stdc++.h> using namespace st ...
- C#------如何取出exe运行文件给客户使用
1.将解决方案配置里面的“Debug”转换成“Release” 2.右击“解决方案”,选着“重新生成解决方案”,以得到最新的版本 3.找到工程目录下的“bin”文件夹,里面有“Release”文件夹, ...
- linux配置oracle11G监听及本地网络服务 及 数据库建库
配置监听及本地网络服务 在oracle用户的图形界面oracle用户中,新开启一个终端,输入命令netca 会弹出如下界面. 数据库建库 在oracle用户的图形界面oracle用户中,新开启一个终端 ...