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. Tomcat8.0 JDK1.8 的详细配置 Win10

    官网下载 先安装JDK以及JRE 之后安装Tomcat jdk配置环境变量: 用户变量:path:C:\Program Files\Java\jdk1.8.0_161\bin     ( jdk安装的 ...

  2. Oracle 实现查询不区分大小写(SQL实现)

    转为小写  LOWER('ABC') 结果 abc转为大写  UPPER('aBc') 结果 ABC 将数据库字段数据和前台接受的值全部转换为大写或者小写 例: select * from table ...

  3. 集训第五周动态规划 D题 LCS

    Description In a few months the European Currency Union will become a reality. However, to join the ...

  4. 解决Antimalware Service Executable CPU,内存占用高的问题

    1.win键+R键打开运行对话框框,输入gpedit.msc打开本地组策略编辑器(组策略):2.依次打开计算机配置-管理模板-Windows组件-Windows Defender:3.如果要关闭Win ...

  5. 关于SQL Server 的限制

    经常被人问到关于SQL Server 的连接数限制, 或者最大的文件大小, 或者标准版和企业版的区别,以及Express上的 其实这些问题都可以在MSDN 上直接找到 SQL Server 2014 ...

  6. 图论算法——最短路径Dijkstra,Floyd,Bellman Ford

    算法名称 适用范围 算法过程 Dijkstra 无负权 从s开始,选择尚未完成的点中,distance最小的点,对其所有边进行松弛:直到所有结点都已完成 Bellman-Ford 可用有负权 依次对所 ...

  7. noip模拟赛 Nephren Ruq Insania

    题目背景 大样例下发链接: https://pan.baidu.com/s/1nuVpRS1 密码: sfxg 注意:本题大样例4的输出文件修改为 https://pan.baidu.com/s/1b ...

  8. fastcgi与cgi的区别[转载]

    cgi 在2000年或更早的时候用得比较多, 以前web服务器一般只处理静态的请求,如果碰到一个动态请求怎么办呢?web服务器会根据这次请求的内容,然后会fork一个新进程来运行外部c程序 (或per ...

  9. Thinkphp5.0 的请求方式

    Thinkphp5.0 的请求方式 方法一(使用框架提供的助手函数): public function index(){ $request = request(); dump($request); } ...

  10. Form表单的action和onSubmit示例介绍

    action是form的属性,onSubmit为事件,要说执行的先后顺序,个人理解是onSubmit在先. 第一:action是form的属性,html5已经将其定义为必需的属性值,onSubmit为 ...