zoj 3822(概率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.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)的更多相关文章
- zoj 3822 概率dp
/* 题目大意:一个n*m的棋盘,每天放一个棋子,每行每列至少有一个棋子时结束.求达到每行每列至少有一个棋子的天数的数学期望. */ #include <iostream> #includ ...
- zoj 3822 Domination(dp)
题目链接:zoj 3822 Domination 题目大意:给定一个N∗M的棋盘,每次任选一个位置放置一枚棋子,直到每行每列上都至少有一枚棋子,问放置棋子个数的期望. 解题思路:大白书上概率那一张有一 ...
- ZOJ 3822 可能性DP
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3822 本场比赛之前,我记得.见WALK概率路DP称号.那么它应该是可以考虑 ...
- zoj 3329 概率dp
题意:有三个骰子,分别有k1,k2,k3个面.每个面值为1--kn每次掷骰子,如果三个面分别为a,b,c则分数置0,否则加上三个骰子的分数之和.当分数大于n时结束.求游戏的期望步数.初始分数为0 链接 ...
- zoj 3640 概率dp
题意:一只吸血鬼,有n条路给他走,每次他随机走一条路,每条路有个限制,如果当时这个吸血鬼的攻击力大于等于某个值,那么就会花费t天逃出去,否则,花费1天的时间,并且攻击力增加,问他逃出去的期望 用记忆化 ...
- 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 难度: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 ...
随机推荐
- linux下的文档处理及tar命令
1.使用cat命令进行纵向合并 使用‘>’是将左边的内容覆盖到右边 使用‘>>’是将左边的内容追加到右边文档中 还可使用‘>’将不同文件进行合并 2.管道符‘|’统计行数 使用 ...
- python 用 PIL 模块 画验证码
PIL 简单绘画 def get_code_img(request): from PIL import Image, ImageDraw, ImageFont import random def ra ...
- LeetCode(6) ZigZag Conversion
题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows li ...
- 使用HTML,CSS快速导出数据到Excel
在应用中经常会遇到要从系统或数据库中导出数据平面文件,一般是导出到txt,csv或excel.txt和csv一般用在系统间的数据交换, 而excel一般有较好的显示效果,可以按照一定的模板导出,导出就 ...
- restful(3):认证、权限、频率 & 解析器、路由控制、分页、渲染器、版本
models.py中: class UserInfo(models.Model): name = models.CharField(max_length=32) psw = models.CharFi ...
- sql 日期问题从周转换到日期
alter procedure p_date@year int=2005, --年份@week int=33, --第几周@firstday datetime =null output, ...
- [网络流24题] 方格取数问题(cogs 734)
«问题描述:在一个有m*n 个方格的棋盘中,每个方格中有一个正整数.现要从方格中取数,使任意2 个数所在方格没有公共边,且取出的数的总和最大.试设计一个满足要求的取数算法.«编程任务:对于给定的方格棋 ...
- 【POJ3680】Intervals(费用流)
题意:有n条线段,每条有起点,终点和一个权值 要求选取一些线段,使它们的权值和最大,并且使每一个点被覆盖不超过k次 1 ≤ K ≤ N ≤ 200 1 ≤ ai < bi ≤ 100,000, ...
- hdu - 1689 Just a Hook (线段树区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...
- [bzoj1578][Usaco2009 Feb]Stock Market 股票市场_完全背包dp
Stock Market 股票市场 bzoj-1578 Usaco-2009 Feb 题目大意:给定一个$S\times D$的大矩阵$T$,其中$T[i][j]$表示第i支股票第j天的价格.给定初始 ...