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 ...
随机推荐
- 使用PNotify构建消息弹窗
参考地址 官网:http://sciactive.com/pnotify/ GitHub:https://github.com/sciactive/pnotify npm仓库:https://www. ...
- windows下自己常用的几个bat
1.samba映射盘符和解除 net use Z: "\\sambaserver ip\dir" "password" /user:"username ...
- hibernate笔记(四)
目标: 一.hibernate查询 二.hibernate对连接池的支持 三.二级缓存 一.hibernate查询 1. 查询概述 1) Get/load主键查询 2) 对象导航查询 3) HQL查询 ...
- [Leetcode] Best time to buy and sell stock 买卖股票的最佳时机
Say you have an array for which the i th element is the price of a given stock on day i. If you were ...
- git使用笔记(七)版本回退和撤销
By francis_hao Nov 21,2016 从版本库初始化开始,每一步的撤销操作 添加第一个文件 在空的版本库中创建了一个文件并git add到了缓存区,这时候怎么撤销呢? 撤销单个文 ...
- Unable to start activity ComponentInfo{com.example.administrator.myapplication/com.example.administrator.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XM
本来就是把fragment写死在activity的xml模板里面,结果报了这个错误, Unable to start activity ComponentInfo{com.example.admini ...
- TCP ------ TCP四次挥手(断开连接)及断开过程
1.正常情况下,调用close(),产生的其中一个效果就是发送FIN,只有双方都调用close(),才会出现正常的四次挥手. 2.如果是服务器,发起四次挥手是在关闭accept()返回的套接字,而不是 ...
- 初识 spl_autoload_register
spl_autoload_register 一.首先我们看来自官网的定义 版本要求:php版本为5.1.2+ 说明:注册给定的函数作为__autoload的实现.即自动加载 函数参数说明: bool ...
- css3 新旧伸缩盒的异同
由于不需要理会IE浏览器,伸缩盒(flexible box)移动端开发中非常好用! 工作中使用APICLOUD开发手机App,老板要求兼容到安卓2.3(新版的需要安卓4.4以上),所以一直使用的是旧版 ...
- 转:深入理解javascript原型和闭包系列
转自:深入理解javascript原型和闭包系列 从下面目录中可以看到,本系列有16篇文章,外加两篇后补的,一共18篇文章.写了半个月,从9月17号开始写的.每篇文章更新时,读者的反馈还是可以的,虽然 ...