ZOJ Problem Set - 3822

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.666666666666

Author: JIANG, Kai

Source: The 2014 ACM-ICPC Asia Mudanjiang Regional Contest

题意:n*m的棋盘中,每下一个棋子会把棋子所在位置的x,y轴覆盖

每天放一个棋子,问所需天数的期望

dp[k][i][j]表上k天覆盖了i条x轴,j条y轴的概率

dp[k][i][j]=dp[k-1][i-1][j-1]*t1+dp[k-1][i][j-1]*t2+dp[k-1][[i][j-1]*t3+dp[k-1][i][j]*t4;

t1 t2 t3 t4对应的概率

特别注意的是只有当i<n||j<m 的时候 dp[k-1][i][j]才有效

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#include<string.h>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int INF=0x3f3f3f3f;
const double eps=0.0000000001;
const int N=+;
const ll mod=1e9+;
double dp[N*N][N][N];
int main(){
int n,m;
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
memset(dp,,sizeof(dp));
dp[][][]=;
for(int k=;k<=n*m;k++){
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
double t1=,t2=,t3=,t4=;
double tt=n*m-k+;
t1=1.0*(n*m-(i-)*m-(j-)*(n-i+))/(tt);
t2=1.0*(n*j-(i-)*j)/(tt);
t3=1.0*(m*i-(j-)*i)/(tt);
t4=1.0*(i*j-k+)/(tt);
dp[k][i][j]+=dp[k-][i-][j-]*t1;
dp[k][i][j]+=dp[k-][i-][j]*t2;
dp[k][i][j]+=dp[k-][i][j-]*t3;
if(i<n||j<m)
dp[k][i][j]+=dp[k-][i][j]*t4;
}
}
}
double ans=;
for(int i=;i<=n*m;i++){
ans=ans+dp[i][n][m]*i;
}
printf("%.11f\n",ans);
}
}

zoj 3822(概率dp)的更多相关文章

  1. zoj 3822 概率dp

    /* 题目大意:一个n*m的棋盘,每天放一个棋子,每行每列至少有一个棋子时结束.求达到每行每列至少有一个棋子的天数的数学期望. */ #include <iostream> #includ ...

  2. zoj 3822 Domination(dp)

    题目链接:zoj 3822 Domination 题目大意:给定一个N∗M的棋盘,每次任选一个位置放置一枚棋子,直到每行每列上都至少有一枚棋子,问放置棋子个数的期望. 解题思路:大白书上概率那一张有一 ...

  3. ZOJ 3822 可能性DP

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3822 本场比赛之前,我记得.见WALK概率路DP称号.那么它应该是可以考虑 ...

  4. zoj 3329 概率dp

    题意:有三个骰子,分别有k1,k2,k3个面.每个面值为1--kn每次掷骰子,如果三个面分别为a,b,c则分数置0,否则加上三个骰子的分数之和.当分数大于n时结束.求游戏的期望步数.初始分数为0 链接 ...

  5. zoj 3640 概率dp

    题意:一只吸血鬼,有n条路给他走,每次他随机走一条路,每条路有个限制,如果当时这个吸血鬼的攻击力大于等于某个值,那么就会花费t天逃出去,否则,花费1天的时间,并且攻击力增加,问他逃出去的期望 用记忆化 ...

  6. zoj 3822 Domination (概率dp 天数期望)

    题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...

  7. ZOJ 3822 Domination(概率dp 牡丹江现场赛)

    题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...

  8. ZOJ 3822 Domination 概率dp 难度:0

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  9. zoj 3822 Domination 概率dp 2014牡丹江站D题

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

随机推荐

  1. Python之使用eval()函数将字符串的数据结构提取出来

    data = input('请输入你要修改的对象:').strip() ''' 输入下面的字典列表 [{'backend':'www.oldboy1.org','record':{'server':' ...

  2. Python安装配置

    Python下载 官网下载地址:https://www.python.org/downloads/windows/ 下载安装包: python-3.5.0-amd64(64位).exe python- ...

  3. [luoguP2401] 不等数列

    传送门 f[i][j]表示前i个数有j个<的方案数 #include <cstdio> #define N 1001 #define p 2015 int n, k; int f[N ...

  4. [luoguP2444] [POI2000]病毒(AC自动机 + dfs)

    传送门 先把所有串建一个AC自动机, 如果要找一个不包含任意一个串的串, 说明这个串一直在AC自动机上匹配但匹配不到, 也就是说,匹配时除去val值为1的点,除去fail指针指向val值为1的点,是否 ...

  5. hdu3592(差分约束) (线性)

    题意:一些牛按序号排成一条直线,有两种要求,A和B距离不得超过X,还有一种是A和B距离不得少于Y,问1和N可能的最大距离. 和poj那题一样,就是多了多组数据. #include<cstring ...

  6. Github上600多个iOS开源项目分类及介绍

    将Github上600多个iOS开源项目进行分类并且有相应介绍,小伙伴们快来看呀 地址:http://github.ibireme.com/github/list/ios/

  7. LOJ#539. 「LibreOJ NOIP Round #1」旅游路线

    n<=100,m<=1000的图,在此图上用油箱容量C<=1e5的车来旅行,旅行时,走一条边会耗一单伟油,在点i时,若油量<ci,则可以把油以pi的价格补到ci,pi<= ...

  8. gulp基本语法

    pipe:用管道输送 1.gulp.src(glops[, options]) 输出(Emits)符合所提供的匹配模式(glob)或者匹配模式的数组(array of globs)的文件. 将返回一个 ...

  9. 洛谷 U41572 Portal2

    U41572 Portal2 题目背景 某地ENLIGHTENED的XM研究所正在研究Portal的处理法则,想要揭示XM能量的来源以及应用XM能量.ENLIGHTENED的首席科学家Jacks发现其 ...

  10. JDBC的Statement对象

    以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/statements.html: 一旦获得了数据库的连接,就可以和数据库进行交互.JDBC的Statem ...