ZOJ 3822 Domination 概率dp 难度:0
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
概率dp
#include<cstdio>
#include<cstring>
using namespace std;
double dp[60][60][3000];
void printdp(int x,int y){
for(int i=0;i<=x;i++){
for(int j=0;j<=y;j++){
for(int k=0;k<=i*j;k++){
printf("dp[%d][%d][%d]%f ",i,j,k,dp[i][j][k]);
}
}
puts("");
}
}
int main(){
int T;
int n,m;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
memset(dp[i][j],0,sizeof(dp[i][j]));
}
}
dp[0][0][0]=1;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
for(int k=0;k<=i*j;k++){
if(k==n*m||(i==n&&j==m)) continue;
if(k<i*j)dp[i][j][k+1]+=dp[i][j][k]*(i*j-k)/(n*m-k);
if(i<n)dp[i+1][j][k+1]+=dp[i][j][k]*(n-i)*j/(n*m-k);
if(j<m)dp[i][j+1][k+1]+=dp[i][j][k]*(m-j)*i/(n*m-k);
if(i<n&&j<m)dp[i+1][j+1][k+1]+=dp[i][j][k]*(n-i)*(m-j)/(n*m-k);
}
}
}
double sum=0;
for(int k=0;k<=n*m;k++){
sum+=k*dp[n][m][k];
// sum+=dp[n][m][k];
// printf("dp[%d]%f\n",k,dp[n][m][k]);
}
//printdp(n,m);
//double ans=(double)sub/(double)sum;
printf("%.12f\n",sum);
}
return 0;
}
ZOJ 3822 Domination 概率dp 难度:0的更多相关文章
- zoj 3822 Domination 概率dp 2014牡丹江站D题
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- zoj 3822 Domination (概率dp 天数期望)
题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...
- ZOJ 3822 Domination(概率dp)
一个n行m列的棋盘,每天可以放一个棋子,问要使得棋盘的每行每列都至少有一个棋子 需要的放棋子天数的期望. dp[i][j][k]表示用了k天棋子共能占领棋盘的i行j列的概率. 他的放置策略是,每放一次 ...
- ZOJ 3822 Domination(概率dp 牡丹江现场赛)
题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...
- zoj 3822(概率dp)
ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Ju ...
- ZOJ 3822 Domination 期望dp
Domination Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...
- zoj 3822 Domination (可能性DP)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ZOJ - 3822 Domination (DP)
Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays chess ...
- CF 148D Bag of mice 概率dp 难度:0
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
随机推荐
- UVa 12627 Erratic Expansion - 分治
因为不好复制题目,就出给出链接吧: Vjudge传送门[here] UVa传送门[here] 请仔细看原题上的那幅图,你会发现,在时间t(t > 0),当前的气球构成的一幅图,它是由三个时间为( ...
- Python3基础 super 子类调用父类的__init__
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- UVA 3942 Remember the Word (Trie+DP)题解
思路: 大白里Trie的例题,开篇就是一句很容易推出....orz 这里需要Trie+DP解决. 仔细想想我们可以得到dp[i]=sum(dp[i+len[x]]). 这里需要解释一下:dp是从最后一 ...
- Windows 上安装 pip
1 从 https://pypi.python.org/pypi/pip#downloads 下载安装包 pip-9.0.1.tar.gz 2 解压 pip-9.0.1.tar.gz 3 用CMD ...
- NOIP2018 退役记
NOIP挂完,OI再见 AFO Day 0 早上的高铁,1点多到广州,2点多到酒店,下午就是颓颓颓,然后晚上随便刷了一下板子,反正PJ也没啥板子可以刷 就这样浪费了一天,我到底在干嘛 Day 1 早上 ...
- [POJ1958][Strange Tower of Hanoi]
题目描述 求解 \(n\) 个盘子 \(4\) 座塔的 Hanoi 问题最少需要多少步 问题分析 考虑 \(3\) 座塔的 Hanoi 问题,记 \(f[i]\) 表示最少需要多少步, 则 \(f[i ...
- UVa 1471 防线
https://vjudge.net/problem/UVA-1471 题意:给出一个序列,删除一个连续子序列,使得剩下的序列中有一个长度最大的连续递增子序列,输出个数. 思路:首先可以计算出以i结尾 ...
- Loadrunner安装详解
安装 1. 运行"setup.exe" 2. 点击安装,其中会有提示缺少"Microsoft Visual C++ 2005 SP1运行组件",下载这 个组件. ...
- Asp.net Ajax(ashx)
主要实现 ajax分页功能 效果图 后台方法代码展示 /// <summary> /// WebAjax处理类 /// </summary> public class WebA ...
- shuoj 418 丢史蒂芬妮(素数筛+sg函数)
丢史蒂芬妮 代码: #include<bits/stdc++.h> using namespace std; +; int SG[N][N]; bool S[N]; vector<i ...