LA 6972 Domination
6972 Domination 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的矩阵,每天随机的在未放棋子的格子上放一个棋子。求每行至少有一个棋子,每列至少有一个棋子的天数的期望
(1 <= N, M <= 50).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
#define SC scanf
#define CT continue
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
const int mod=100000000; double dp[55][55][2505];
int main()
{
int cas,n,m;SC("%d",&cas);
while(cas--){
SC("%d%d",&n,&m);
MM(dp,0);
dp[0][0][0]=1;
dp[1][1][1]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
for(int k=max(i,j);k<=i*j;k++){
int t=n*m-(k-1);
double p1=dp[i][j][k-1]*(i*j-(k-1))/t;
double p2=dp[i-1][j][k-1]*(n-(i-1))*j/t;
double p3=dp[i][j-1][k-1]*(m-(j-1))*i/t;
double p4=dp[i-1][j-1][k-1]*(n-(i-1))*(m-(j-1))/t;
dp[i][j][k]=p1+p2+p3+p4;
}
double ans=0;
for(int i=max(n,m);i<=n*m;i++)
ans+=i*(dp[n][m][i]-dp[n][m][i-1]);
printf("%.12f\n",ans);
}
return 0;
}
LA 6972 Domination的更多相关文章
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
- Le lié à la légèreté semblait être et donc plus simple
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...
- 2014牡丹江D Domination
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- Mac Pro 使用 ll、la、l等ls的别名命令
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...
- Linux中的动态库和静态库(.a/.la/.so/.o)
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...
- Mac OS使用ll、la、l等ls的别名命令
在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...
- .Uva&LA部分题目代码
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...
- zoj3822 Domination(概率dp)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- 获取在线人数 CNZZ 和 51.la
string Cookies = string.Empty; /// <summary> /// 获取在线人数 (51.la统计器) /// </summary> /// &l ...
随机推荐
- 【模板】C++高精度加法
所谓高精度加法就是对两个和可能会超过long long数据范围的数进行加法运算.这种情况下,显然不能使用常规的方法进行运算. 那么,不妨考虑一下人在纸上是如何进行加法运算的.当人进行加法运算时,通常会 ...
- HDU 3333-Turing Tree-线段树+离散+离线
Description After inventing Turing Tree, 3xian always felt boring when solving problems about interv ...
- Closest Common Ancestors (Lca,tarjan)
午时刷题,难甚,遂小憩于桌上,惊醒,于梦中有所得,虽大声曰:吾已得tarjan之奥秘! 关于tarjan算法,其实就是一个递归加并查集的应用. 大致代码: #include<bits/stdc+ ...
- __formart__
__format__ 一.__format__ 自定制格式化字符串 date_dic = { 'ymd': '{0.year}:{0.month}:{0.day}', 'dmy': '{0.day}/ ...
- win10系统查看激活状态及是否永久激活
查看windows系统是否激活 找到“此电脑”,右击“属性” 查看windows系统是否永久激活 第一种方法 win+r 进入运行,输入slmgr.vbs -xpr 如图,再点击确定. 弹出一个对话 ...
- Jobs(二) Servlet的配置
折腾了一会,终于实现了:在浏览器中输入数据,然后在Java类中取出输出,并使浏览器重定向(接收一个request,返回一个response). 这里有几个问题需要详细记录一下. 首先是request的 ...
- IOS 改变UISearchBar的背景色
之前网上提供的方法试了很多种 都不能很好的去掉背景色 ,修改背景色方法如下: searchbar.barStyle = UIBarStyleBlackTranslucent; searchbar. ...
- IOS开发copy,nonatomic, retain,weak,strong用法
readwrite 是可读可写特性;需要生成getter方法和setter方法时 readonly 是只读特性 只会生成getter方法 不会生成setter方法 ;不希望属性在类外改变 ass ...
- vue模板字符串写法
1.模板字符串拼接id <div class="thumbnail" :id="`ctrol_${item.id}`"> <i :class= ...
- iphone SprintBoard部分私有API总结(不支持iOS8)
本文介绍iOS SrpintBoard框架的部分私有API,具体包括: 获取ios上当前正在运行的所有App的bundle id(不管当前程序是在前台还是后台都可以) 获取ios上当前前台运行的App ...