2014牡丹江区域赛D(概率DP)ZOJ3822

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 <= NM <= 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

题意:RT

思路:dp[k][i][j]表示下了k个棋子,还有i行j列没有棋子的概率

转移分四种情况转移即可

只举例一种情况,可以在(i+1)*(m-j)里的格子任选一个走,总的可以选的格子数为(n*m-k+1)

所以 dp[k][i][j] + =dp[k-1][i+1][j] * (i+1)*(m-j)  / (n*m-k+1)

时间: 2024-10-11 19:31:42

2014牡丹江区域赛D(概率DP)ZOJ3822的相关文章

zoj 3822 Domination(2014牡丹江区域赛D题)

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 chessboar

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

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

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

Description Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. It is also known as postfix notation since every operator in an expression follows all of its operands. Bob is a student in

zoj 3827 Information Entropy(2014牡丹江区域赛I题)

Information Entropy Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Information Theory is one of the most popular courses in Marjar University. In this course, there is an important chapter about information entropy. Entropy is t

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

题目链接:ZOJ 3827 Information Entropy 根据题目的公式算吧,那个极限是0 AC代码: #include <stdio.h> #include <string.h> #include <math.h> const double e=exp(1.0); double find(char op[]) { if(op[0]=='b') return 2.0; else if(op[0]=='n') return e; else if(op[0]=='

zoj 3819(2014牡丹江区域赛 A题 )

题意:给出A班和B班的学生成绩,如果bob(A班的)在B班的话,两个班级的平均分都会涨.求bob成绩可能的最大,最小值. A班成绩平均值(不含BOB)>A班成绩平均值(含BOB) && B班成绩平均值(不含BOB)< B班成绩平均值(含BOB) 化简后得 B班成绩平均值(不含BOB) < X < A班成绩平均值(不含BOB) Sample Input 24 35 5 54 4 36 55 5 4 5 31 3 2 2 1Sample Output 4 42 4 1

2014牡丹江区域赛B(树的直径)ZOJ3820

Building Fire Stations Time Limit: 5 Seconds      Memory Limit: 131072 KB      Special Judge Marjar University is a beautiful and peaceful place. There are N buildings and N - 1 bidirectional roads in the campus. These buildings are connected by road

2014牡丹江区域赛H(字典树)ZOJ3826

Hierarchical Notation Time Limit: 2 Seconds      Memory Limit: 131072 KB In Marjar University, students in College of Computer Science will learn EON (Edward Object Notation), which is a hierarchical data format that uses human-readable text to trans

2014牡丹江区域赛K(贪心)ZOJ3829

Known Notation Time Limit: 2 Seconds      Memory Limit: 131072 KB Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. It is also known as postfix notation since every operator in an expre