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. ZOJ 3229 Shoot the Bullet

    Shoot the Bullet Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origin ...

  2. redis-ubuntu环境下安装

    ubuntu环境下联网安装 进去系统后,首先修改root的密码 命令 sudo passwd 设置新的密码:XXX 切换为root操作 $ wget http://download.redis.io/ ...

  3. LayoutParams继承于Android.View.ViewGroup.LayoutParams.

    LayoutParams相当于一个Layout的信息包,它封装了Layout的位置.高.宽等信息.假设在屏幕上一块区域是由一个Layout占领的,如果将一个View添加到一个Layout中,最好告诉L ...

  4. 英语发音规则---H字母

    英语发音规则---H字母 一.总结 一句话总结: 1.H发[h]音? hot [hɒt] adj. 热的 house [haʊs] n. 住宅 head [hed] n. 头:头痛 hat [hæt] ...

  5. linux 下Redis 5.0主从复制(一主二从)哨兵模式的搭建

    文档结构如下: 一.环境说明: 作用 IP地址 端口 操作系统版本 安装目录 哨兵文件 主库 172.16.10.80 6379 Redhat 6.7 /redis5.0/redis-5.0.0 Se ...

  6. Docker运行程序报错 WARNING: IPv4 forwarding is disabled. Networking will not work

    WARNING: IPv4 forwarding is disabled. Networking will not work.   第一步:vi /usr/lib/sysctl.d/00-system ...

  7. Session会在浏览器关闭后消失吗?

    转  http://blog.csdn.net/rongwenbin/article/details/51784310 Cookie的两种类型   在项目开发中我们时常将需要在客户端(浏览器)缓存的数 ...

  8. Vue运行npm run dev 时修改端口

    进入项目文件的config文件夹E:\myapp\myproject\config,找到index.js,修改里面的8080端口,改成8088(确定不被别的程序使用的都可以)

  9. SQL Server-聚焦聚集索引对非聚集索引的影响

      前言 在学习SQL 2012基础教程过程中会时不时穿插其他内容来进行讲解,相信看过SQL Server 2012 T-SQL基础教程的童鞋知道前面写的所有内容并非都是摘抄书上内容,如若是这样那将没 ...

  10. SSH 项目中 用Hibernate底层 简单的封装DAO层

    废话不多少了,主要是使用hibernate的查询方法,自己封装了DAO层,供service来方便使用. 首先:必须要继承的 public class CommonDao extends Hiberna ...