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
题意:
说有个傻孩子喜欢痴迷下象棋,并且有一个习惯,每一天随机放一只棋子在(n*m)的棋盘的随意一个位子里。问当满足任意一行以及任意一列都有棋子时。
再不放了。问这样随机放棋子直到放不了棋子平均需要多少天..... 用DP【i】【j】【k】表示前i行有棋子,前j列有棋子,并且在放了k个棋子的情况下
的概率,对于DP【i】【j】【k】此刻的状态等于上一状态的和......
推了很久也没有退出这个转移方程..看了一下解题报告,才发下逗比的忘记算dp[i-1][j-1][k-1]这一种情况...
代码:
 //#define LOCAL
#include<cstdio>
#include<cstring>
#define maxn 55
double dp[maxn][maxn][maxn*maxn];
int n,m;
int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
int cas,i,j,k;
scanf("%d",&cas);
while(cas--)
{
scanf("%d%d",&n,&m);
int tt=n*m;
memset(dp,,sizeof(dp));
dp[][][]=;
for(i=;i<=n;i++)
{
//表示前i行有旗子
for(j=;j<=m;j++)
{
//表示前j列有棋子
for(k=;k<=tt;k++)
{
//当n行m列中都有棋子时
if(i==n&&j==m)
dp[i][j][k]=(dp[i-][j][k-]*(n-i+)*j+dp[i][j-][k-]*(m-j+)*i+dp[i-][j-][k-]*(n-i+)*(m-j+))/(tt-k+);
else
dp[i][j][k]=(dp[i-][j][k-]*(n-i+)*j+dp[i][j-][k-]*(m-j+)*i+dp[i-][j-][k-]*(n-i+)*(m-j+)+dp[i][j][k-]*(i*j-k+))/(tt-k+);
}
}
}
double ans=;
for(int i=;i<=n*m;i++)
ans+=dp[n][m][i]*i; //得到期望
printf("%.8lf\n",ans);
}
return ;
}

zoj3822 Domination(概率dp)的更多相关文章

  1. zoj3822 Domination 概率dp --- 2014 ACM-ICPC Asia Mudanjiang Regional Contest

    一个n行m列的棋盘,每次能够放一个棋子.问要使得棋盘的每行每列都至少有一个棋子 须要的放棋子次数的期望. dp[i][j][k]表示用了k个棋子共能占据棋盘的i行j列的概率. 那么对于每一颗棋子,在现 ...

  2. ZOJ 3822 Domination 概率dp 难度:0

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  3. zoj 3822 Domination 概率dp 2014牡丹江站D题

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  4. zoj 3822 Domination (概率dp 天数期望)

    题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...

  5. ZOJ 3822 Domination(概率dp 牡丹江现场赛)

    题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...

  6. ZOJ 3822 Domination(概率dp)

    一个n行m列的棋盘,每天可以放一个棋子,问要使得棋盘的每行每列都至少有一个棋子 需要的放棋子天数的期望. dp[i][j][k]表示用了k天棋子共能占领棋盘的i行j列的概率. 他的放置策略是,每放一次 ...

  7. ZOJ3822 ACM-ICPC 2014 亚洲杯赛事现场牡丹江司D称号Domination 可能性DP

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  8. Domination(概率DP)

    Domination 题目链接:https://odzkskevi.qnssl.com/9713ae1d3ff2cc043442f25e9a86814c?v=1531624384 Edward is ...

  9. zoj 3822(概率dp)

    ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Ju ...

  10. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

随机推荐

  1. DevExpress Crack

    开发者论坛 DevExpressComponents-16.1.6.16270.exe http://www.dxper.net/thread-7440-1-1.html http://www.dxp ...

  2. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Python基础学习笔记(六)常用列表操作函数和方法

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-lists.html 3. http://www.liaoxuef ...

  4. css position 绝对定位和相对定位

    position:absolute这个是绝对定位:是相对于浏览器的定位.比如:position:absolute:left:20px;top:80px; 这个容器始终位于距离浏览器左20px,距离浏览 ...

  5. web工程中各类地址写法的总结

    首先打一个"/" //如果地址给服务器用,那么"/"就代表该web应用 , 如果给浏览器用的,那么"/"就代表网站(其下有多个web应用) ...

  6. placeholder在不同浏览器下的表现及兼容方法(转)

    1.什么是placeholder?    placeholder是html5新增的一个属性,当input或者textarea设置了该属性后,该值的内容将作为灰字提示显示在文本框中,当文本框获得焦点(或 ...

  7. u盘在电脑读不出来,但别的可以读,别的u盘在我电脑又可以识别怎么回事?

    不知道我的U盘是怎么回事,在我自己的电脑里读不出来,下面有U盘图标,但我的电脑里就是找不到U盘盘符,但把这个U盘放其他电脑上又可以读取,我以为是我的电脑的问题,但用其他的U盘插我电脑又没问题,完全摸不 ...

  8. Android生命周期和Service生命周期

    android生命周期 运行:oncreate → onstart → onresume暂停:onresume → onpause:再次运行:onresume停止:onpause → onstop → ...

  9. svn提交代码的原则

    [1]先更新在提交 [2]多提交 [3]不要提交不能通过编译的代码 [4]每次提交必须书写明晰的标注 [5]提交时注意不要提交本地自动生成的文件 [6]不要提交自己不明白的代码 [7]慎用锁定功能

  10. PHP 用文件流方式展示图片

    public function index(){ $img = 'http://img.pf.loc/static/images/2016/05/24/21d98edf98bd6c30afe1c838 ...