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 思路:题目的意思是求树上的两点,使得树上其余的点到其中一个点的 ...
随机推荐
- Markdown编辑器简单总结
字体大小: #1 ##2 添加链接: 文字链接 [blog](http://yalantis.com/blog/how_we_created_tab_bar_animation_for_ios/?ut ...
- [JavaEE] Entity中Lazy Load的属性序列化JSON时报错
The server encountered an internal error that prevented it from fulfilling this request.org.springfr ...
- JS-DOM2级事件对象跨浏览器处理(已封装)
var eventUill = { //添加事件 addHander: function(element, type, handler) { if(element.addEventListener) ...
- JS-纯js制作动态成绩表(流程控制语句+js内置对象)
流程控制for循环+if判断+Math对象+Array对象+Date对象制作成绩表 <!DOCTYPE html><html> <head> <meta ch ...
- NXP Mifare S50标准IC卡- 访问位(Access Bits) 分析
Mifare S50 标准IC卡有1K 字节的EEPROM,主要用来存储数据和控制信息.1K 字节的EEPROM分成16 个区,每区又分成4 段,每1段中有16 个字节.每个区的最后一个段叫“尾部&q ...
- 复习---JS-Array 对象
要开始做第一个js练习了.前面三个小题都是数组的.先来复习一下数组.如下是W3C上面的关于数组的内容. 之前笔记中的内容:http://www.cnblogs.com/lal-fighting/p/5 ...
- wcf第1步
添加System.ServiceModel 引用 Wcf 服务端 class Program { static void Main(string[] args) { ServiceHost host ...
- setInterval js
$('#start_scan').on('click',function(){ if(timer == undefined){ timer = setInterval(scan,1000) start ...
- nodejs fs module
fs.watchFile(filename[, options], listener)# Added in: v0.1.31 filename <String> | <Buffer& ...
- Python学习笔记——基本语法
1.程序输出——print语句 >>> myString = 'Hello World!' >>> print myString Hello World! > ...