zoj3822 Domination(概率dp)
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 <= 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
题意:
说有个傻孩子喜欢痴迷下象棋,并且有一个习惯,每一天随机放一只棋子在(n*m)的棋盘的随意一个位子里。问当满足任意一行以及任意一列都有棋子时。
再不放了。问这样随机放棋子直到放不了棋子平均需要多少天..... 用DP【i】【j】【k】表示前i行有棋子,前j列有棋子,并且在放了k个棋子的情况下
的概率,对于DP【i】【j】【k】此刻的状态等于上一状态的和......
推了很久也没有退出这个转移方程..看了一下解题报告,才发下逗比的忘记算dp[i-1][j-1][k-1]这一种情况...
代码:
//#define LOCAL
#include<cstdio>
#include<cstring>
#define maxn 55
double dp[maxn][maxn][maxn*maxn];
int n,m;
int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
int cas,i,j,k;
scanf("%d",&cas);
while(cas--)
{
scanf("%d%d",&n,&m);
int tt=n*m;
memset(dp,,sizeof(dp));
dp[][][]=;
for(i=;i<=n;i++)
{
//表示前i行有旗子
for(j=;j<=m;j++)
{
//表示前j列有棋子
for(k=;k<=tt;k++)
{
//当n行m列中都有棋子时
if(i==n&&j==m)
dp[i][j][k]=(dp[i-][j][k-]*(n-i+)*j+dp[i][j-][k-]*(m-j+)*i+dp[i-][j-][k-]*(n-i+)*(m-j+))/(tt-k+);
else
dp[i][j][k]=(dp[i-][j][k-]*(n-i+)*j+dp[i][j-][k-]*(m-j+)*i+dp[i-][j-][k-]*(n-i+)*(m-j+)+dp[i][j][k-]*(i*j-k+))/(tt-k+);
}
}
}
double ans=;
for(int i=;i<=n*m;i++)
ans+=dp[n][m][i]*i; //得到期望
printf("%.8lf\n",ans);
}
return ;
}
zoj3822 Domination(概率dp)的更多相关文章
- zoj3822 Domination 概率dp --- 2014 ACM-ICPC Asia Mudanjiang Regional Contest
一个n行m列的棋盘,每次能够放一个棋子.问要使得棋盘的每行每列都至少有一个棋子 须要的放棋子次数的期望. dp[i][j][k]表示用了k个棋子共能占据棋盘的i行j列的概率. 那么对于每一颗棋子,在现 ...
- ZOJ 3822 Domination 概率dp 难度:0
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- zoj 3822 Domination 概率dp 2014牡丹江站D题
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 牡丹江现场赛)
题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...
- ZOJ 3822 Domination(概率dp)
一个n行m列的棋盘,每天可以放一个棋子,问要使得棋盘的每行每列都至少有一个棋子 需要的放棋子天数的期望. dp[i][j][k]表示用了k天棋子共能占领棋盘的i行j列的概率. 他的放置策略是,每放一次 ...
- ZOJ3822 ACM-ICPC 2014 亚洲杯赛事现场牡丹江司D称号Domination 可能性DP
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- Domination(概率DP)
Domination 题目链接:https://odzkskevi.qnssl.com/9713ae1d3ff2cc043442f25e9a86814c?v=1531624384 Edward is ...
- zoj 3822(概率dp)
ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Ju ...
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
随机推荐
- 【转载】CMake 简介和 CMake 模板
转载自我的博客: CMake 简介和 CMake 模板 . 如果你用 Linux 操作系统,使用 cmake 会简单很多,可以参考一个很好的教程: CMake 入门实战 | HaHack .如果你用 ...
- Shifting List Item Values From One List To Another In Oracle Forms
Suppose you have two T-List items in form and you want to shift element values from one list to ano ...
- Java EE 在网页输出九九乘法表
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- MemSQL Start[c]UP 2.0 - Round 1(无聊练手B题)
http://codeforces.com/contest/452/problem/B B. 4-point polyline time limit per test 2 seconds memo ...
- 百度翻译word-wrap,页面错乱原因查找过程(已修复)
今天群里有人发问, 进入百度翻译http://fanyi.baidu.com/#auto/zh/, 输入word-wrap,发现页面错乱. 寻找错乱原因. 上图 开始查找原因: 1.从请求入手 从ch ...
- SQL Povit
),) ,,@logistics_code='All',@fee_type='All' ),) ,@strDateList='',@from_date=cast((ltrim(@yr)+'-'+ltr ...
- Ubuntu 通过Deb安装 MySQL5.5(转载)
1. 下载 MySQL 5.5 deb 安装包 cd /usr/local/src sudo wget -O mysql-5.5.22-debian6.0-i686.deb http://dev.my ...
- bootstrap学习笔记<十一>(导航条)
基础导航条.样式:class="navbar navbar-default",属性:role="navigation" <div class=" ...
- 使用ioctl“实现”自定义的系统调用
http://www.educity.cn/Linux/1242138.html 最近做的项目跟Linux内核的关系比较大,我们的项目需要在用户态触发一些内核态的代码运行.众所周知,内核态的代码是不能 ...
- caffe的data_reader.cpp分析一下干了点什么
首先说明:下面的内容不一定对 类body: 变量:LayerParameter param_ :它里面放的是:body传进来的layerparameter的参数: BlockingQueue<s ...