ZOJ 3288 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 <= 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能力太弱了,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的更多相关文章
- 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 ...
- zoj 3822 Domination(dp)
题目链接:zoj 3822 Domination 题目大意:给定一个N∗M的棋盘,每次任选一个位置放置一枚棋子,直到每行每列上都至少有一枚棋子,问放置棋子个数的期望. 解题思路:大白书上概率那一张有一 ...
- 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(2014牡丹江区域赛D称号)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ZOJ 3822 Domination 概率dp 难度:0
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ZOJ 3822 Domination (三维概率DP)
E - Domination Time Limit:8000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu Submi ...
- zoj 3822 Domination(2014牡丹江区域赛D题) (概率dp)
3799567 2014-10-14 10:13:59 Acce ...
- zoj 3822 Domination 概率dp 2014牡丹江站D题
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
随机推荐
- @Autowired @Resource @Inject 自动注入
一.@AutoWired ( spring 的注解 )自动注入 /** * @Autowired: * 默认按照 Student 类型去容器中找对应的组件:applicationContext.get ...
- poj 2955 区间dp入门题
第一道自己做出来的区间dp题,兴奋ing,虽然说这题并不难. 从后向前考虑: 状态转移方程:dp[i][j]=dp[i+1][j](i<=j<len); dp[i][j]=Max(dp[i ...
- valueof这个万能方法,将string转换为int或者int转换为string都可以
private static String testString = "111"; int stringInt = Integer.valueOf(testString); Str ...
- 笔试题&面试题:给定n个数,要求比較次数1.5n同一时候找出最大值和最小值
写出一个算法,对给定的n个数的序列,返回序列中的最大和最小的数. 设计出一个算法,仅仅须要运行1.5n次比較就能找到序列中最大和最小的数吗?是否能再少? 分析:要求比較次数为1.5n,使用一般的逐个遍 ...
- Log4J日志配置具体解释
一.Log4j简单介绍 Log4j有三个基本的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综 ...
- hdoj--3062--party(2-sat 可行解)
Party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- [jzoj 5661] 药香沁鼻 解题报告 (DP+dfs序)
interlinkage: https://jzoj.net/senior/#contest/show/2703/0 description: solution: 注意到这本质就是一个背包,只是选了一 ...
- block的一些注意事项
1,定义block时是可以同时进行赋值的 2,block中是代码块,就是里面写的是语句,需要加分号 3,在block中,允许有多条语句 4,在带有参数的block中,声明部分参数名可以省略,但是建议写
- php.ini配置文件参数优化
用于生产环境中的PHP需要对其进行优化,让PHP自身发挥更好的性能,除了写好PHP代码,还要配置好php-fpm以及php.ini调优.本文从内存.OPcache.上传.会话以及安全等方面讲解php. ...
- AVL数
平衡二叉树(AVL树) AVL树是一种二叉搜索树,并且每个节点的左右子树高度之差最多为1.AVL树是第一个在最坏的情况下保证以O(logn)的时间进行搜索,插入和删除操作的数据结构,AVL树能在对数时 ...