ZOJ 3288 Domination
Time Limit:8000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu
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
解题:比较简单的一道题,可惜学渣的dp能力太弱了,dp[i][j][k]表示已经覆盖了i行j列且使用了k颗棋子时的概率。。。。
注意转移,放一颗棋子后可能行和列的覆盖数不会增加,也有可能只增加了行,也有可能只增加了列,还有可能同时增加了行列的覆盖数。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
double dp[maxn][maxn][maxn*maxn];
int main() {
int t,n,m;
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
memset(dp,,sizeof(dp));
dp[][][] = ;
for(int i = ; i <= n; ++i){
for(int j = ; j <= m; ++j){
for(int k = max(i,j);k <= i*j; ++k){
double p1 = dp[i][j][k-]*(i*j - k + );//行列覆盖都不增加
double p2 = dp[i-][j][k-]*(n-i+)*j;//增加行
double p3 = dp[i][j-][k-]*i*(m - j + );//增加列
double p4 = dp[i-][j-][k-]*(n - i + )*(m - j + );//既增加行 又增加列
dp[i][j][k] = (p1 + p2 + p3 + p4)/(n*m - k + );
}
}
}
double ans = ;
for(int i = max(n,m); i <= n*m; ++i)
ans += dp[n][m][i]*i - dp[n][m][i-]*i;
printf("%.9f\n",ans);
}
return ;
}
ZOJ 3288 Domination的更多相关文章
- zoj 3288 Domination (可能dp)
///dp[i][j][k]代表i行j列件,并把一k的概率 ///dp[i][j][k]一种常见的方法有四种传输 ///1:dp[i-1][j][k-1] 可能 (n-(i-1))*j/(n*m-(k ...
- zoj 3822 Domination(dp)
题目链接:zoj 3822 Domination 题目大意:给定一个N∗M的棋盘,每次任选一个位置放置一枚棋子,直到每行每列上都至少有一枚棋子,问放置棋子个数的期望. 解题思路:大白书上概率那一张有一 ...
- ZOJ 3822 Domination 期望dp
Domination Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...
- zoj 3822 Domination (可能性DP)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- zoj 3822 Domination(2014牡丹江区域赛D称号)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ZOJ 3822 Domination 概率dp 难度:0
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ZOJ 3822 Domination (三维概率DP)
E - Domination Time Limit:8000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu Submi ...
- zoj 3822 Domination(2014牡丹江区域赛D题) (概率dp)
3799567 2014-10-14 10:13:59 Acce ...
- zoj 3822 Domination 概率dp 2014牡丹江站D题
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
随机推荐
- 流媒体播放器VLC SDL
http://www.cnblogs.com/lihuixian001/archive/2013/03/15/2957103.html https://wiki.videolan.org/Win32C ...
- 页面安装Jre
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height ...
- [SharePoint2010开发入门经典]9创建更好的用户体验----silverlight
本章概要: 1.了解Silverlight 2.理解为什么使用Silverlight 3.介绍如何集成SharePoint和Silverlight
- 在Eclipse中创建Maven多模块项目
在Eclipse中创建Maven多模块项目1,创建多模块项目选择File>New>Project,打开New Project窗口,选择Maven>Maven Project,选择下一 ...
- Codeforces 558B Amr and The Large Array
B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...
- Cocos Code IDE
https://www.cnblogs.com/luorende/p/6464181.html http://www.cocoachina.com/bbs/read.php?tid-464164.ht ...
- DB-MySQL:MySQL 连接的使用
ylbtech-DB-MySQL:MySQL 连接的使用 1.返回顶部 1. Mysql 连接的使用 在前几章节中,我们已经学会了如何在一张表中读取数据,这是相对简单的,但是在真正的应用中经常需要从多 ...
- springMVC、mybatis实现的登录页面(maven)
首先项目结构 pom文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:// ...
- const,var,let 区别
js中const,var,let区别 1.const定义的变量不可以修改,而且必须初始化. 声明的是常量 1 const b = 2;//正确 2 // const b;//错误,必须初始化 3 co ...
- 玩转 sublime3 第一弹 文件介绍
安装 官网下载地址:http://www.sublimetext.com/3 本文将以Windows 64 bit 进行讲解. 目录介绍 sublime默认安装之后会生成一个安装目录和数据目录: C: ...