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 思路:题目的意思是求树上的两点,使得树上其余的点到其中一个点的 ...
随机推荐
- jpa注解
http://www.oracle.com/technetwork/cn/middleware/ias/toplink-jpa-annotations-100895-zhs.html#ManyToOn ...
- python 生成器和递归
生成器 1.定义 问题:python会把对象放到内存中,我们每次定义变量.列表等都会在内存中占用对应的地址块,所以当内存容量一定时,列表的容量会受到内存的限制,而且假如我们创建了一个包含200万个元素 ...
- linux安装Mac的默认Monaco字体
Monaco字体是我最喜欢的编程字体,如果你想在linux上面安装,只需要在terminal中执行: curl -kL https://raw.github.com/cstrap/monaco-fon ...
- “K米” 软件产品评测
第一部分 调研,评测 评测: 第一次上手体验:KTV相信很多人都有去过,大部分包厢只有哦一个点歌台,相信很多人都会烦恼于一堆人挤在小小的点歌台前点歌的样子,还有些人不太好意思跑到点歌台点歌,常常是碰到 ...
- 关于markdown的学习
标题 标题(一个等号) 小标题 深层标题 深层标题2 深层标题6 深层标题 左边一个空格 深层标题 左边两个空格 此处省略很多字 左边有回车 一个空格 两个空格 三个空格 十个空格 字体属性:斜体.加 ...
- 墙内无缝更新Android SDK
https://www.caoqq.net/android-sdk-offine-download.html Lucas · 10 个月前 打开Android SDK Manager, 打开设置 2. ...
- json的解释
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.JSON采用完全独立于语言的文本格式,这些特性使JSON成为理想的数据交换语言.易于人阅读和编写,同时也易 ...
- BZOJ3160: 万径人踪灭
设a[i]=bool(s[i]=='a'),b[i]=bool(s[i]=='b'),考虑a和a.b和b的卷积,由于卷积是对称的,就可以统计出不连续回文子串个数了.可能说得比较简略.再用manache ...
- BZOJ4527: K-D-Sequence 线段树
别人家的题解. #include<bits/stdc++.h> #define N 200005 #define M (l+r>>1) #define P (k<< ...
- python设计模式之--单例模式
python的单例模式就是一个类的实例只能自始自终自能创建一次.应用场景比如说数据库的连接池. #!/usr/bin/env python # coding=utf- class Foo(object ...