题目链接:

problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376

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

Author: JIANG, Kai

PS:

附上bin神的概率dp总结 Orz;

http://www.cnblogs.com/kuangbin/archive/2012/10/02/2710606.html

代码例如以下:(学习:http://blog.csdn.net/napoleon_acm/article/details/40020297

//dp[i][j][k] 表示当前用了<=k个chess ,覆盖了i行j列(i*j的格子 每行至少一个。每列至少一个)的概率。
//
//dp[i][j][k] 由 dp[i][j][k-1] , dp[i-1][j][k-1], dp[i][j-1][k-1], dp[i-1][j-1][k-1]得到,
//分别表示 1、加入的新的一个chess, 2、不覆盖新的行列, 3、仅仅新覆盖一行。 仅仅新覆盖一列。
//4、同一时候新覆盖一行和一列,得到dp[i][j][k]。
//递推时。 每一个概率 * (能够覆盖的点数/剩余全部的空点数) 相加得到[i][j][k].
//ans += (dp[n][m][i] - dp[n][m][i-1])* i。 (i = [1, n*m])
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 57;
double dp[maxn][maxn][maxn*maxn];
int main()
{
int n, m;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(dp,0,sizeof(dp));
dp[0][0][0] = 1.0;
for(int i = 1; i <= n; i++)
{
for(int j =1; j <= m; j++)
{
for(int k = 1; k <= n*m; k++)
{
dp[i][j][k] = dp[i][j-1][k-1]*((1.0*i*(m-j+1))/(n*m-k+1))
+dp[i-1][j][k-1]*((1.0*(n-i+1)*j)/(n*m-k+1))
+dp[i-1][j-1][k-1]*((1.0*(n-i+1)*(m-j+1))/(n*m-k+1))
+dp[i][j][k-1]*((1.0*(i*j-k+1))/(n*m-k+1));
}
}
}
double ans = 0;
for(int i = 1; i <= n*m; i++)
{
ans+=(dp[n][m][i]-dp[n][m][i-1])*i;
}
printf("%.12lf\n",ans);
}
return 0;
}

ZOJ 3822 Domination(概率dp 牡丹江现场赛)的更多相关文章

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

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

  2. zoj 3822 Domination(2014牡丹江区域赛D称号)

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

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

    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. ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)

    Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...

  6. ZOJ 3822 Domination(概率dp)

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

  7. zoj 3822(概率dp)

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

  8. ZOJ 3822 Domination 期望dp

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

  9. zoj 3822 Domination (可能性DP)

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

随机推荐

  1. Jetty:配置JSP支持

    选择JSP实现 从Jetty-9.2開始,使用Apache Jasper作为默认JSP容器实现.在前面的版本号中使用的是Glassfish Jasper,在后面的版本号中也能够继续使用它. Jetty ...

  2. Android broadcast

    发送广播而且接受.发送两个广播 Intent intent = new Intent(); intent.setAction("com.wxq.CUSTOM_INTENT"); s ...

  3. android图片压缩的3种方法实例

    android 图片压缩方法: 第一:质量压缩法: private Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = ...

  4. 页面提交错误,页面间参数传递java.lang.NumberFormatException: null

    多次出现这样的错误,在点击一个按钮触发提交整个页面的事件时,总是报错,不止一次出现这样的错误了. 出现这种问题的分析: 1 我们从这个问题的本身来看,java.lang.NumberFormatExc ...

  5. 一个完善的ActiveX Web控件教程

    免费打工仔:一个完善的ActiveX Web控件教程 出自Ogre3D开放资源地带   跳转到: 导航, 搜索 原作者 David Marcionek. 翻译 免费打工仔 这个教程可以帮助你快速开发一 ...

  6. 【大话QT之七】QT序列化操作

    应用需求: 在网盘开发过程中有这样一个需求.即对文件版本号进行控制,即记录文件版本号的更替信息,这里说的更替信息不过记录不同一时候刻的文件变化,即文件的增.删.改.重命名等操作.在每一个待监控的文件夹 ...

  7. 《大数据互联网大规模数据挖掘与分布式处理》阅读笔记(四)-----WEB广告

    作者: 沈慧 目前,许多WEB应用通过广告而维持生计,从在线广告中获益最多的是搜索应用,“adwords”模型就是一种用于搜索查询和广告匹配的模型.这一章介绍了在线广告的相关问题.在线算法.Adwor ...

  8. javascripte (三) 改变html图像

    <script> function changeImage(){ element=document.getElementById("myimage") if (elem ...

  9. 关于Oralce数据库优化的几点总结

    个人理解,数据库性能最关键的因素在于IO,因为操作内存是快速的,但是读写磁盘是速度很慢的,优化数据库最关键的问题在于减少磁盘的IO,就个人理解应该分为物理的和逻辑的优化, 物理的是指oracle产品本 ...

  10. 如何高效地向Redis插入大量的数据(转)

    最近有个哥们在群里问,有一个日志,里面存的是IP地址(一行一个),如何将这些IP快速导入到Redis中. 我刚开始的建议是Shell+redis客户端. 今天,查看Redis官档,发现文档的首页部分( ...