ZOJ-3822
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的位置
- **/
- #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的更多相关文章
- zoj 3822 Domination(dp)
题目链接:zoj 3822 Domination 题目大意:给定一个N∗M的棋盘,每次任选一个位置放置一枚棋子,直到每行每列上都至少有一枚棋子,问放置棋子个数的期望. 解题思路:大白书上概率那一张有一 ...
- 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 可能性DP
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3822 本场比赛之前,我记得.见WALK概率路DP称号.那么它应该是可以考虑 ...
- zoj 3822 Domination(2014牡丹江区域赛D题) (概率dp)
3799567 2014-10-14 10:13:59 Acce ...
- ZOJ 3822(求期望)
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的空棋盘 每一次在上面选择一个空的位置放置一枚 ...
- ZOJ 3822 Domination(概率dp)
一个n行m列的棋盘,每天可以放一个棋子,问要使得棋盘的每行每列都至少有一个棋子 需要的放棋子天数的期望. dp[i][j][k]表示用了k天棋子共能占领棋盘的i行j列的概率. 他的放置策略是,每放一次 ...
- ZOJ 3822 Domination
题意: 一个棋盘假设每行每列都有棋子那么这个棋盘达到目标状态 如今随机放棋子 问达到目标状态的期望步数 思路: 用概率来做 计算第k步达到目标状态的概率 进而求期望 概率计算方法就是dp ...
- [概率dp] ZOJ 3822 Domination
题意: 给N×M的棋盘.每天随机找一个没放过棋子的格子放一个棋子 问使得每一个每列都有棋子的天数期望 思路: dp[i][j][k] 代表放了i个棋子占了j行k列 到达目标状态的期望 然后从 dp[n ...
随机推荐
- [转]dwr3框架学习笔记--简介及原理简介
1.DWR简介 DWR(直接web远程访问),DWR是一个Java库,使服务器上的Java和JavaScript的浏览器进行交互和相互调用尽可能简单. DWR 是一个可以允许你去创建 AJAX WEB ...
- c++单例模式代码分析
单例模式就是一个C++语法精华浓缩的一个体现,有句老话:麻雀虽小五脏俱全!来形容单例非常贴切! 下面的代码分析了如果自己malloc并且memcpy一个单例指针会带来很大危害并如何防止这种情况发生. ...
- Nginx 学习笔记之安装篇
在windows下安装Nginx其实非常简单,只需如下几个步骤: 1. 在Nginx官网下载相应版本的安装程序,上面有最新版.稳定版等各种版本,正式运营的项目建议下载最新的稳定版 2.将下载后的压缩包 ...
- kali linux下的常用bash命令
虚拟机版本默认用户root 密码toor ls:显示当前目录包含的文件及文件夹 ls -l:以常规格式显示当前目录包含的文件及文件夹(开头字母解释:d:目录 -:文件 c:设备文件 l:链接 b:块设 ...
- 【bzoj4619】[Wf2016]Swap Space 贪心
题目描述 你有许多电脑,它们的硬盘用不同的文件系统储存数据.你想要通过格式化来统一文件系统.格式化硬盘可能使它的容量发生变化.为了格式化,你需要买额外的硬盘.当然,你想要买容量最小的额外储存设备以便省 ...
- P1712 [NOI2016]区间
题目描述 在数轴上有 NN 个闭区间 [l_1,r_1],[l_2,r_2],...,[l_n,r_n][l1,r1],[l2,r2],...,[ln,rn] .现在要从中选出 MM 个区 ...
- mii-tool与ethtool的用法详解
mii-tool与ethtool的用法详解 1.mii-tool 配置网络设备协商方式的工具: 感谢原文作者!原文地址:http://blog.chinaunix.net/uid-20639775-i ...
- 安徽师大附中%你赛day4T1 金字塔 解题报告
金字塔 题目背景: \(Zdrcl\)带着妹子们来到了胡夫金字塔周边旅游, 发现这里正在进行一个有关金字塔的游戏 题目描述: 游戏规则如下: 1. 这里的金字塔是一个 \(N\) 阶的二维金字塔. 2 ...
- 你是否彻底了解margin属性?
写css,你少不了与margin打交道.你真的了解margin吗?你知道margin有什么特性吗?你知道什么是垂直外边距合并?margin在块元素.内联元素中的区别?什么时候该用padding而不是m ...
- rest与restful
知乎上面摘抄的,感觉不错,分享下: https://www.zhihu.com/question/28557115 1. REST描述的是在网络中client和server的一种交互形式:RES ...