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 ...
随机推荐
- linux 进程间消息队列通讯
转自:http://blog.csdn.net/lifan5/article/details/7588529 http://www.cnblogs.com/kunhu/p/3608589.html 前 ...
- java 参数传递是引用传递还是值传递?
JAVA的参数传递倒底是值传递还是引用传递,我觉得两种说法都没错,关键是看怎么理解“引用”和“引用传递”. (一)从编译原理的角度讲,所有那些无法通过形参来修改实参本身的传递机制都是“值传递”,在JA ...
- bzoj1858: [Scoi2010]序列操作
lazy-tag线段树. #include<cstdio> #include<algorithm> #include<cstring> using namespac ...
- android应用分析之apk文件结构
实际上,一个APK文件就是一个.zip格式的压缩包,我们可以用解压缩工具打开任何一个APK文件,由于代码混淆和加密,通过普通解压缩工具打开里面的文件或目录会看到各种乱码.一个典型的ap ...
- (十二)学习CSS之display属性
参考:http://www.w3school.com.cn/cssref/pr_class_display.asp 浏览器支持 所有主流浏览器都支持 display 属性. 注释:如果规定了 !DOC ...
- C# 中 string.Empty、""、null的区别
原文C# 中 string.Empty."".null的区别 一.string.Empty 和 "" 1.Empty是string类中的一个静态的只读字段,它是 ...
- ChineseCounter.cs 统计中文文本中常用字占比
http://www.tuicool.com/articles/qmMba2 1 using System; using System.IO; using System.Collections.Gen ...
- java Object类学习
/* * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETA ...
- Unix 基础IO
内核通过文件描述符引用打开的文件,通常通过open函数或者create函数返回文件描述符. 基本函数: unix中基础的文件操作函数只有5个,分别是open,close,lseek,read,writ ...
- STL(pair map set vector priority_queue) poj 3297
POJ 3297 算法竞赛初级杂烩包 题意:学生选课,没个学生只能选一门课.大写字符是课的名字,小写是人名.如果课程后面有多个相同名字算一个,如果一个人选多门课,则他选不上课,输出课和每门课选课人数 ...