ZOJ 3822 Domination(概率dp 牡丹江现场赛)
题目链接: 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 <= 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
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 牡丹江现场赛)的更多相关文章
- zoj 3822 Domination 概率dp 2014牡丹江站D题
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- zoj 3822 Domination(2014牡丹江区域赛D称号)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ZOJ 3822 Domination 概率dp 难度:0
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- zoj 3822 Domination (概率dp 天数期望)
题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...
- ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)
Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...
- ZOJ 3822 Domination(概率dp)
一个n行m列的棋盘,每天可以放一个棋子,问要使得棋盘的每行每列都至少有一个棋子 需要的放棋子天数的期望. dp[i][j][k]表示用了k天棋子共能占领棋盘的i行j列的概率. 他的放置策略是,每放一次 ...
- zoj 3822(概率dp)
ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Ju ...
- ZOJ 3822 Domination 期望dp
Domination Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...
- zoj 3822 Domination (可能性DP)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
随机推荐
- Ppoj 1014 深搜
这个题题意是给你价值1-6的珠宝个数输出能否平分为两份(如果平分为三分就不知道怎么做了……) 主要是用回溯DFS,但是要剪枝,对200取模……!!(很重要……) 代码…… #include <i ...
- SilkTest Q&A 8
Q72.如何在一个testplan中运行所有的testcase? A72. 1.打开testplan 2.点击Run/Run All Tests菜单,SilkTest开始执行testplan中所有的t ...
- 不同数据库oracle mysql SQL Server DB2 infomix sybase分页查询语句
在不同数据库中的使用的分页查询语句: 当前页:currentpage 页大小:pagesize 1. Oracle数据库 select * from (select A.*,rownum rn fro ...
- VC/MFC 在ListCtl 控件中随鼠标移动提示单元格信息
BEGIN_MESSAGE_MAP(CTipListCtrl, CListCtrl) //{{AFX_MSG_MAP(CTipListCtrl) ON_WM_MOUSEMOVE() ON_WM_DES ...
- 用XCA(X Certificate and key management)可视化程序管理SSL 证书(2)--生成SSL证书请求
在上个章节中,我们提到了怎样安装XCA(X Certificate and key management)程序.这个章节我们開始正式介绍怎样用XCA生成证书请求.假设大家用过java的话.肯定知道jd ...
- JS-JavaScript学习笔记(一)
javaScript 1.文档的输出:document.write() 可输出字符,表达式,html标签.函数 2.不论什么类型和字符串相加,都会被转换成字符串类型. 比如:var i=5; var ...
- SQLite/嵌入式数据库
SQLite/嵌入式数据库 的项目要么不使用数据库(一两个文配置文件就可以搞定),要么就会有很多的数据,用到 postgresql,操练sqlite的还没有.现在我有个自己的小测试例子,写个数据库对比 ...
- HTML5文件上传还有进度条
以下是自学it网--中级班上课笔记 网址:www.zixue.it 需要在chrome,ff,IE10下运行 html页面 <!DOCTYPE html> <html lang=&q ...
- qt qml中PropertyAnimation的几种使用方法
qml文章 qt qml中PropertyAnimation的几种使用方法 动画应用场景有以下几种: 首先如果一个Rectangle.动画是要改变它的x和y值 1,Rectangle一旦被创建,就要移 ...
- Qt中提高sqlite的读写速度(使用事务一次性写入100万条数据)
SQLite数据库本质上来讲就是一个磁盘上的文件,所以一切的数据库操作其实都会转化为对文件的操作,而频繁的文件操作将会是一个很好时的过程,会极大地影响数据库存取的速度.例如:向数据库中插入100万条数 ...