D - 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 <= NM <= 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的更多相关文章

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

  2. zoj 3822 Domination(dp)

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

  3. ZOJ 3822 Domination 期望dp

    Domination Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...

  4. zoj 3822 Domination (可能性DP)

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

  5. zoj 3822 Domination(2014牡丹江区域赛D称号)

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

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

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

  7. ZOJ 3822 Domination (三维概率DP)

    E - Domination Time Limit:8000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submi ...

  8. zoj 3822 Domination(2014牡丹江区域赛D题) (概率dp)

    3799567 2014-10-14 10:13:59                                                                     Acce ...

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

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

随机推荐

  1. asp.net core 2.1开发环境下配置IIS

    asp.net core 2.1是可以在开发环境下配置到IIS中的,这样就可以在vs中按F5直接运行了 在项目上右键点击属性,然后在Debug中配置如下参数 首先点击New按钮,输入IIS,点击确定 ...

  2. [叁]Pomelo游戏server编程分享 之 server结构与配置分析

    网络部署结构 我们先看一下Pomeloserver网络部署情况,直接上图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3RiaW56aQ==/font/ ...

  3. Python 对Twitter tweet的元素 (Word, Screen Name, Hash Tag)的词汇多样性分析

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-3 @author: guaguastd @name: tw ...

  4. MongoDB初探系列之四:MongoDB与Java共舞

    因为版本号不同,可能API也有所不同.本次学习用的是3.0版本号. 1.使用的mongodb的jdbc驱动版本号为:mongo-java-driver-3.0.0.jar 2.本节仅仅是简介JDBC操 ...

  5. Java集合(二):List列表

    在上一节中,介绍了Java集合的总体情况.从这节開始,将介绍详细的类.这里不单单介绍类的使用方法.还会试图从源代码的角度分析类的实现.这一节将介绍List接口及实现类.即列表中的链表LinkedLis ...

  6. SGU 531 - Bonnie and Clyde 预处理+二分

    Bonnie and Clyde Description Bonnie and Clyde are into robbing banks. This time their target is a to ...

  7. Swift - 判断是否有某功能访问权限,没有则提示,并自动跳转到设置页

    由于 iOS 系统的安全限制,App 如果需要访问设备的通讯录.麦克风. 相册. 相机.地理位置等时,需要请求用户是否允许访问.   有时用户不小心点了“不允许”,后面可能就不知道要去哪里再开启这个权 ...

  8. 使用CNN做电影评论的负面检测——本质上感觉和ngram或者LSTM同,因为CNN里图像检测卷积一般是3x3,而文本分类的话是直接是一维的3、4、5

    代码如下: from __future__ import division, print_function, absolute_import import tensorflow as tf impor ...

  9. POJ 1543 暴搜

    题意:输出a^3=b^3+c^3+d^3的所有a,b,c,d的值. b,c,d由小到大且b,c,d都大于1. 思路: 按照题意写就好.... // by SiriusRen #include < ...

  10. COM基础

    为什么说COM的可重用性是建立在二进制级别? COM本身是语言无关,它的标准建立在二进制级别.对于使用COM组件的客户程序,它只需要要使用的COM对象信息就可以通过COM库的帮助创建和使用COM对象, ...