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
题意:
说有个傻孩子喜欢痴迷下象棋,并且有一个习惯,每一天随机放一只棋子在(n*m)的棋盘的随意一个位子里。问当满足任意一行以及任意一列都有棋子时。
再不放了。问这样随机放棋子直到放不了棋子平均需要多少天..... 用DP【i】【j】【k】表示前i行有棋子,前j列有棋子,并且在放了k个棋子的情况下
的概率,对于DP【i】【j】【k】此刻的状态等于上一状态的和......
推了很久也没有退出这个转移方程..看了一下解题报告,才发下逗比的忘记算dp[i-1][j-1][k-1]这一种情况...
代码:
 //#define LOCAL
#include<cstdio>
#include<cstring>
#define maxn 55
double dp[maxn][maxn][maxn*maxn];
int n,m;
int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
int cas,i,j,k;
scanf("%d",&cas);
while(cas--)
{
scanf("%d%d",&n,&m);
int tt=n*m;
memset(dp,,sizeof(dp));
dp[][][]=;
for(i=;i<=n;i++)
{
//表示前i行有旗子
for(j=;j<=m;j++)
{
//表示前j列有棋子
for(k=;k<=tt;k++)
{
//当n行m列中都有棋子时
if(i==n&&j==m)
dp[i][j][k]=(dp[i-][j][k-]*(n-i+)*j+dp[i][j-][k-]*(m-j+)*i+dp[i-][j-][k-]*(n-i+)*(m-j+))/(tt-k+);
else
dp[i][j][k]=(dp[i-][j][k-]*(n-i+)*j+dp[i][j-][k-]*(m-j+)*i+dp[i-][j-][k-]*(n-i+)*(m-j+)+dp[i][j][k-]*(i*j-k+))/(tt-k+);
}
}
}
double ans=;
for(int i=;i<=n*m;i++)
ans+=dp[n][m][i]*i; //得到期望
printf("%.8lf\n",ans);
}
return ;
}

zoj3822 Domination(概率dp)的更多相关文章

  1. zoj3822 Domination 概率dp --- 2014 ACM-ICPC Asia Mudanjiang Regional Contest

    一个n行m列的棋盘,每次能够放一个棋子.问要使得棋盘的每行每列都至少有一个棋子 须要的放棋子次数的期望. dp[i][j][k]表示用了k个棋子共能占据棋盘的i行j列的概率. 那么对于每一颗棋子,在现 ...

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

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

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

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

  4. zoj 3822 Domination (概率dp 天数期望)

    题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...

  5. ZOJ 3822 Domination(概率dp 牡丹江现场赛)

    题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...

  6. ZOJ 3822 Domination(概率dp)

    一个n行m列的棋盘,每天可以放一个棋子,问要使得棋盘的每行每列都至少有一个棋子 需要的放棋子天数的期望. dp[i][j][k]表示用了k天棋子共能占领棋盘的i行j列的概率. 他的放置策略是,每放一次 ...

  7. ZOJ3822 ACM-ICPC 2014 亚洲杯赛事现场牡丹江司D称号Domination 可能性DP

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

  8. Domination(概率DP)

    Domination 题目链接:https://odzkskevi.qnssl.com/9713ae1d3ff2cc043442f25e9a86814c?v=1531624384 Edward is ...

  9. zoj 3822(概率dp)

    ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Ju ...

  10. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

随机推荐

  1. CodeForces 490C Hacking Cypher

    Hacking Cypher Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Sub ...

  2. Cheatsheet: 2013 11.12 ~ 11.30

    Mobile Xcode 5 Essentials Android vs. iOS Development: Fight! Using MVC to Understand ASP.NET, iOS, ...

  3. nohup不输出日志信息的方法,及linux重定向学习

    起因 最近使用nohup创建了一个后台进程,默认日志输出到了nohup.out文件中,程序跑起来也就没再管,过了大约一周,发现硬盘空间不够了,于是查找原因,发现这个nohup.out文件已经到了70G ...

  4. Freebie: Date Picker Calendar Demo Form For Oracle Forms 6i

    I have already posted and provided the required PLSQL Library and the Calendar FMX file in my previo ...

  5. jQuery插件之jquery editable plugin--点击编辑文字插件

    jeditable是一个jquery插件,它的优点是可以就地编辑,并且提交到服务器处理,是一个不可多得的就地编辑插件.(注: 就地编辑,也有称即时编辑?一般的流程是这样的,当用户点击网页上的文字时,该 ...

  6. Mybatis的二级缓存配置

    一个项目中肯定会存在很多共用的查询数据,对于这一部分的数据,没必要每一个用户访问时都去查询数据库,因此配置二级缓存将是非常必要的.  Mybatis的二级缓存配置相当容易,要开启二级缓存,只需要在你的 ...

  7. hihoCoder太阁最新面经算法竞赛17

    比赛链接:http://hihocoder.com/contest/hihointerview26 A.排序后枚举两个点,确定一个矩形后二分剩下两个点. #include <bits/stdc+ ...

  8. C#窗体->>随机四则运算

    用户需求: 程序能接收用户输入的整数答案,并判断对错程序结束时,统计出答对.答错的题目数量.补充说明:0——10的整数是随机生成的用户可以选择四则运算中的一种用户可以结束程序的运行,并显示统计结果.在 ...

  9. CUBRID学习笔记 31 通过select创建表

    语法 CREATE {TABLE | CLASS} <table_name> [( <column_definition> [,<table_constraint> ...

  10. HDU 5813 Elegant Construction(优雅建造)

    HDU 5813 Elegant Construction(优雅建造) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65 ...