ZOJ 3822 Domination 期望dp
Domination
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3822
Description
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 dominatedby 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
HINT
题意
每次这个人会随机选择一个空格子扔棋子,然后问你期望扔多少次,可以把n*m的矩阵,每一行和每一列都至少有一个棋子
题解:
期望dp,用容斥做
dp[i][j][k]表示占领了i行j列,用了k个
@)1%KBO0HM418$J94$1R.jpg)
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
#include <bitset>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std;
const int maxn = + ;
double dp[maxn][maxn][maxn*maxn];
int n , m ; inline double GetDouble(int x)
{
return (double)x;
} void initiation()
{
memset(dp,-,sizeof(dp));
scanf("%d%d",&n,&m);
} double dfs(int x,int y,int k)
{
if(dp[x][y][k]> -0.5) return dp[x][y][k];
double & ans = dp[x][y][k] = ;
if(x == n && y == m ) return ans;
int all = m*n-k;
if(x*y != k) ans += dfs(x,y,k+)*GetDouble(x*y-k)/GetDouble(all);
if(x != n && y != m) ans += dfs(x+,y+,k+)*GetDouble((n-x)*(m-y))/GetDouble(all);
if(x != n && y != ) ans += dfs(x+,y,k+)*GetDouble(y*(n-x))/GetDouble(all);
if(y != m && x != ) ans += dfs(x,y+,k+)*GetDouble(x*(m-y))/GetDouble(all);
ans += ;
return ans;
} double solve()
{
return dfs(,,);
} int main(int argc,char *argv[])
{
int Case;
scanf("%d",&Case);
while(Case--)
{
initiation();
printf("%.12lf\n",solve());
}
return ;
}
ZOJ 3822 Domination 期望dp的更多相关文章
- zoj 3822 Domination (概率dp 天数期望)
题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...
- 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)
一个n行m列的棋盘,每天可以放一个棋子,问要使得棋盘的每行每列都至少有一个棋子 需要的放棋子天数的期望. dp[i][j][k]表示用了k天棋子共能占领棋盘的i行j列的概率. 他的放置策略是,每放一次 ...
- zoj 3822 Domination (可能性DP)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ZOJ - 3822 Domination (DP)
Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays chess ...
- ZOJ 3822 Domination 概率dp 难度:0
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ZOJ 3822 Domination(概率dp 牡丹江现场赛)
题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...
- 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 ...
随机推荐
- Playing with cubes II
Description: Hey Codewarrior! You already implemented a Cube class, but now we need your help again! ...
- Maven、gradle、Ant、Eclipse IDE
Maven.gradle.Ant.Eclipse IDE之间的关系 http://wenku.baidu.com/view/d33208810912a21615792910.html?from=sea ...
- 从Excel表格导入数据到数据库
数据库:SQL 1.小数据直接粘贴 2.用导入向导 3.用SSIS包 4.用SQL语句 现在详细说一下第4种方法,以.xlsx文件为例 .xlsx文件需要用provider“Microsoft.ACE ...
- Innodb物理存储结构系列1
本篇先介绍 下Innodb表空间,文件相关的内存数据结构. 1. 数据结构 Innodb的tablespace和文件的关系,是一对多的关系,先来看三个结构体 1. fil_system_struct: ...
- P2P编程(十)
此为网络编程的一个系列,后续会把内容补上....
- POJ 3648 Wedding (2-SAT,经典)
题意:新郎和新娘结婚,来了n-1对夫妻,这些夫妻包括新郎之间有通奸关系(包括男女,男男,女女),我们的目地是为了满足新娘,新娘对面不能坐着一对夫妻,也不能坐着有任何通奸关系的人,另外新郎一定要坐新娘对 ...
- disabled
http://blog.csdn.net/dinglang_2009/article/details/6974887 如果把页面viewstate设为disabled 那么 ispost就一直为fal ...
- 用JS动态创建登录表单,报了个小错误
后来发现原来是: dvObj.style.border='#Red 1px sold'; 其中的Red多谢了一个‘#’, 但是奇怪的是在chrome和firefox都备有报错,但是在ie中报错了. 各 ...
- 通过history.pushState无刷新改变url
通过history.pushState无刷新改变url 背景 在浏览器中改变地址栏url,将会触发页面资源的重新加载,这使得我们可以在不同的页面间进行跳转,得以浏览不同的内容.但随着单页应用的增多,越 ...
- HDU 5285 wyh2000 and pupil
题意:有一群人,已知某两人之间互相不认识,要把这群人分成两部分,每部分至少一人,且在每部分内没有人互不认识. 解法:图染色.某场bestcoder第二题……看完题觉得是个二分图……完全不会二分图什么的 ...