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 思路:题目的意思是求树上的两点,使得树上其余的点到其中一个点的 ...
随机推荐
- Scala高阶函数示例
object Closure { def function1(n: Int): Int = { val multiplier = (i: Int, m: Int) => i * m multip ...
- codevs 1001 舒适的路线(Kruskal)
传送门 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N(1<N≤500)个景点(编号为1,2,3,…,N),这些景点被M(0<M≤5 ...
- 解决Eclipse 项目报错:Unbound classpath container
Eclipse出现下面两条报错: The project cannot be built until build path errors are resolved HelloWord Unknown ...
- Java 开发技巧
一 读取配置文件 1 Properties读取配置文件 编写配置文件config.properties放在普通java工程的src目录(如果是maven工程就放在工程的src/main/resourc ...
- BZOJ2157: 旅游
传送门 先讲一个悲伤地故事 RunID User Problem Result Memory Time Language Code_Length Submit_Time 1635823 Cydiate ...
- gnuplot conditional plotting: plot col A:col B if col C == x
http://stackoverflow.com/questions/6564561/gnuplot-conditional-plotting-plot-col-acol-b-if-col-c-x H ...
- Linux开放1521端口允许网络连接Oracle Listene
症状:1. TCP/IP连接是通的.可以用ping 命令测试. 2. 服务器上Oracle Listener已经启动. lsnrctl status 查看listener状态 lsnrctl s ...
- 自然语言14_Stemming words with NLTK
https://www.pythonprogramming.net/stemming-nltk-tutorial/?completed=/stop-words-nltk-tutorial/ # -*- ...
- logo上传
- %1 不是有效的Win32应用程序
用 64bit 的 Python 调用 32bit 的 Dll 会出错