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 <= NM <= 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的位置
**/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <stdio.h>
using namespace std;
#define maxn 60
double dp[maxn * maxn][maxn][maxn];
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n, m;
memset(dp, , sizeof(dp));
scanf("%d %d", &n, &m);
dp[][][] = 1.0;
for(int i = ; i < n * m; i++)
{
for(int j = ; j <= n; j++)
{
for(int k = ; k <= m; k++)
{
dp[i + ][j + ][k + ] += dp[i][j][k] * (n - j) * (m - k) / (n * m - i);
dp[i + ][j][k + ] += dp[i][j][k] * j * (m - k) / (n * m - i);
dp[i + ][j + ][k] += dp[i][j][k] * (n - j) * k / (n * m - i);
dp[i + ][j][k] += dp[i][j][k] * (k * j - i) / (n * m - i);
}
}
}
double ans = ;
for(int i = ; i <= n * m; i++)
{
ans += i * (dp[i][n][m] - dp[i - ][n][m]);
}
printf("%.10f\n", ans);
}
return ;
}

ZOJ-3822的更多相关文章

  1. zoj 3822 Domination(dp)

    题目链接:zoj 3822 Domination 题目大意:给定一个N∗M的棋盘,每次任选一个位置放置一枚棋子,直到每行每列上都至少有一枚棋子,问放置棋子个数的期望. 解题思路:大白书上概率那一张有一 ...

  2. zoj 3822(概率dp)

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

  3. ZOJ 3822 Domination 期望dp

    Domination Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...

  4. ZOJ 3822 可能性DP

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3822 本场比赛之前,我记得.见WALK概率路DP称号.那么它应该是可以考虑 ...

  5. zoj 3822 Domination(2014牡丹江区域赛D题) (概率dp)

    3799567 2014-10-14 10:13:59                                                                     Acce ...

  6. ZOJ 3822(求期望)

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

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

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

  8. ZOJ 3822 Domination(概率dp)

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

  9. ZOJ 3822 Domination

    题意: 一个棋盘假设每行每列都有棋子那么这个棋盘达到目标状态  如今随机放棋子  问达到目标状态的期望步数 思路: 用概率来做  计算第k步达到目标状态的概率  进而求期望  概率计算方法就是dp  ...

  10. [概率dp] ZOJ 3822 Domination

    题意: 给N×M的棋盘.每天随机找一个没放过棋子的格子放一个棋子 问使得每一个每列都有棋子的天数期望 思路: dp[i][j][k] 代表放了i个棋子占了j行k列 到达目标状态的期望 然后从 dp[n ...

随机推荐

  1. servlet入门(1)

    第一个servlet类 1.编写一个java类,继承HttpServlet类 2.重写doget和dopost方法 3.Servlet程序在tomcat服务器运行 第一步:找到server窗口,并新建 ...

  2. element-ui的el-tabel组件怎么使用type=“expand”实现表格嵌套并且在子表格没有数据的时候隐藏展开按钮

    效果如下: 试过很多种办法,思路都在怎么控制<el-table-column type="expand">里面的type上,比如使用v-show等等,但是发现,要不就是 ...

  3. hihocoder 1465 循环串匹配问题(后缀自动机)

    后缀自动机感觉好万能 tries图和ac自动机能做的,后缀自动机很多也都可以做 这里的循环匹配则是后缀自动机能做的另一个神奇功能 循环匹配意思就是S是abba, T是abb 问'abb', 'bba' ...

  4. 【题解】NOI2009二叉查找树 + NOIP2003加分二叉树

    自己的思维能力果然还是太不够……想到了这棵树所有的性质即中序遍历不变,却并没有想到怎样利用这一点.在想这道题的过程中走入了诸多的误区,在这里想记录一下 & 从中吸取到的教训(原该可以避免的吧) ...

  5. [ZJOI2005]沼泽鳄鱼 矩阵乘法

    ---题面--- 题解: 乍一看还是挺懵逼的.和HH去散步很像,思路也是类似的. 复制一段我在HH去散步的题解里面写的一段话吧: 考虑f[i][j]表示i和j是否右边相连,有为1,否则为0,那么f同时 ...

  6. fis难用的地方

    1. 刷新不同步,刷新的结果是前一次的修改结果2. 刷新时间非常长3. 有些代码打包不兼容,例如tween这个库,有函数yoyo:function yoyo(yoyo){}的形式,不能正确打包,会报[ ...

  7. BZOJ 3262: 陌上花开 CDQ

    这个题大部分人用了离散然后水之,然而.....作为一只蒟蒻我并没有想到离散,而是直接拿两个区间一个对应n,一个对应k来搞,当然这两个区间是对应的,我把第一维排序,第二维CDQ,第三维树状数组,然而由于 ...

  8. 从零开始学习MXnet(五)MXnet的黑科技之显存节省大法

    写完发现名字有点拗口..- -# 大家在做deep learning的时候,应该都遇到过显存不够用,然后不得不去痛苦的减去batchszie,或者砍自己的网络结构呢? 最后跑出来的效果不尽如人意,总觉 ...

  9. Django请求原理

    总结一下: 1. 进来的请求转入/hello/. 2. Django通过在ROOT_URLCONF配置来决定根URLconf. 3. Django在URLconf中的所有URL模式中,查找第一个匹配/ ...

  10. There is an overlap in the region chain

    ERROR: (regions day_hotstatic,860010-2355010000_20140417_12_entry_00000000321,1398674475358.0dc20573 ...