3799567 2014-10-14 10:13:59                                                                     Accepted                                                             3822 C++ 1870 71760 njczy2010
3799566 2014-10-14 10:13:25                                                                     Memory Limit Exceeded                                                             3822 C++ 0 131073 njczy2010

sign,,,太弱了,,,

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

Author: JIANG, Kai

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<string>
//#include<pair> #define N 55
#define M 1000005
#define mod 1073741824
//#define p 10000007
#define mod2 100000000
#define ll long long
#define LL long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int T;
int n,m;
double dp[N][N][N*N];
double ans;
int tot; void ini()
{
ans=;
memset(dp,,sizeof(dp));
scanf("%d%d",&n,&m);
tot=n*m;
} void solve()
{
int i,j,k;
dp[][][]=;
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(i== && j==) continue;
for(k=max(i,j);k<=i*j;k++){
//printf(" i=%d j=%d k=%d dp=%.5f add=%.5f\n",i,j,k,dp[i][j-1][k-1],dp[i][j-1][k-1]*(m-j)*i/(tot-(k-1)));
if(i==n && j==m){
dp[i][j][k]=dp[i-][j][k-]*(n-i+)*j/(tot-(k-))
+dp[i][j-][k-]*(m-j+)*i/(tot-(k-))
+dp[i-][j-][k-]*(n-i+)*(m-j+)/(tot-(k-));
}
else
dp[i][j][k]=dp[i-][j][k-]*(n-i+)*j/(tot-(k-))
+dp[i][j-][k-]*(m-j+)*i/(tot-(k-))
+dp[i-][j-][k-]*(n-i+)*(m-j+)/(tot-(k-))
+dp[i][j][k-]*(i*j-(k-))/(tot-(k-));
// printf(" aft i=%d j=%d k=%d dp=%.5f\n",i,j,k,dp[i][j][k]);
}
}
}
//for(i=1;i<=n;i++){
// for(j=1;j<=m;j++){
// for(k=max(i,j);k<=i*j;k++){
// printf(" i=%d j=%d k=%d dp=%.5f\n",i,j,k,dp[i][j][k]);
// }
// }
// } for(k=;k<=tot;k++){
ans+=dp[n][m][k]*k;
}
} void out()
{
printf("%.10f\n",ans);
} int main()
{
// freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
scanf("%d",&T);
// for(int ccnt=1;ccnt<=T;ccnt++)
while(T--)
// while(scanf("%s",s1)!=EOF)
{
//if(n==0 && k==0 ) break;
//printf("Case %d: ",ccnt);
ini();
solve();
out();
} return ;
}

zoj 3822 Domination(2014牡丹江区域赛D题) (概率dp)的更多相关文章

  1. ZOJ 3822 ( 2014牡丹江区域赛D题) (概率dp)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 题意:每天往n*m的棋盘上放一颗棋子,求多少天能将棋盘的每行每列都至少有 ...

  2. ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)

    Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...

  3. ACM学习历程——ZOJ 3829 Known Notation (2014牡丹江区域赛K题)(策略,栈)

    Description Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathema ...

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

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

  5. The 2014 ACM-ICPC Asia Mudanjiang Regional Contest(2014牡丹江区域赛)

    The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 题目链接 没去现场.做的网络同步赛.感觉还能够,搞了6题 A:这是签到题,对于A堆除掉.假设没剩余 ...

  6. ZOJ 3827 Information Entropy (2014牡丹江区域赛)

    题目链接:ZOJ 3827 Information Entropy 依据题目的公式算吧,那个极限是0 AC代码: #include <stdio.h> #include <strin ...

  7. 2014 牡丹江区域赛 B D I

    http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358 The 2014 ACM-ICPC Asia Mudanj ...

  8. zoj 3820(2014牡丹江现场赛B题)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5374 思路:题目的意思是求树上的两点,使得树上其余的点到其中一个点的 ...

  9. 2014 牡丹江现场赛 i题 (zoj 3827 Information Entropy)

    I - Information Entropy Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %l ...

随机推荐

  1. shell脚本,awk实现行列转换

    [root@localhost study]# cat file 张三 语文 张三 数学 李四 语文 李四 数学 王五 语文 王五 数学 王五 英语 怎么实现为下面的排序??? 语文 数学 语文 数学 ...

  2. OpenCV Haar AdaBoost源码改进据说是比EMCV快6倍

    <pre name="code" class="cpp">#include "Haar.h" #include "lo ...

  3. java在线聊天项目1.1版 ——开启多个客户端,分别实现注册和登录功能,使用客户端与服务端信息request机制,重构线程,将单独的登录和注册线程合并

    实现效果图: eclipse项目中初步整合之前的各个客户端和服务端的窗口与工具类,效果如下图: 已将注册服务器线程RegServer功能放到LoginServer中,使用客户端与服务端的request ...

  4. java在线聊天项目0.3版本 制作客户端窗体,实现发送按钮和回车发送信息功能,使用ActionListener监听事件中actionPerformed方法(用内部类和匿名内部类两种方法)

    方法一,使用匿名内部类的监听方法,因方法一致代码稍冗余 package com.swift; import java.awt.BorderLayout; import java.awt.Color; ...

  5. 对于WebAssembly编译出来的.wasm文件js如何调用

    WebAssembly也叫浏览器字节码技术 这里就不过多的解释了网上很多介绍 主要是让大家知道在js里面如何调用执行它,我之前看WebAssemblyAPI时候反正是看得一脸懵逼 也是为了大家能更快的 ...

  6. PHP 线上项目 无法操作

    部署到线上的项目,http 环境没有问题,首页展示没有问题,但是跳转页面展示到了本地, 解决办法 : 更改文件夹所属用户 chown -R apache:apache html

  7. (12)zabbix agent 类型所有key

    zabbix服务器端通过与zabbix agent通信来获取客户端服务器的数据,agent分为两个版本,其中一个是主动一个是被动,在配置主机我们可以看到一个是agent,另一个是agent(activ ...

  8. 主DNS服务-正向解析

    环境 准备最少两台主机 一台当DNS服务器,一台当客户机 如:192.168.43.7这台主机当DNS服务器,192.168.43.6这台主机当客户机 安装DNS服务 yum install -y b ...

  9. 文件的软硬链接& 文件编辑vi和vim

    目录 文件的软硬链接 1.软链接 2.硬链接 文件编辑vi和vim 须先安装vim命令的软件包yum install -y vim 三种模式: 1.普通模式 2.编辑模式 3.末行模式 文件的软硬链接 ...

  10. 二、Pandas库与数据处理

    # Author:Zhang Yuan import pandas as pd import numpy as np #Pandas提供了两大数据结构:一维结构的Series类型.二维结构的DataF ...