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 <= NM <= 50).

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <vector>
  7. #include <queue>
  8. #include <stack>
  9. #include <map>
  10. #include <algorithm>
  11. #include <set>
  12. using namespace std;
  13. typedef long long ll;
  14. typedef unsigned long long Ull;
  15. #define MM(a,b) memset(a,b,sizeof(a));
  16. #define SC scanf
  17. #define CT continue
  18. const double eps = 1e-10;
  19. const int inf = 0x3f3f3f3f;
  20. const double pi=acos(-1);
  21. const int mod=100000000;
  22.  
  23. double dp[55][55][2505];
  24. int main()
  25. {
  26. int cas,n,m;SC("%d",&cas);
  27. while(cas--){
  28. SC("%d%d",&n,&m);
  29. MM(dp,0);
  30. dp[0][0][0]=1;
  31. dp[1][1][1]=1;
  32. for(int i=1;i<=n;i++)
  33. for(int j=1;j<=m;j++)
  34. for(int k=max(i,j);k<=i*j;k++){
  35. int t=n*m-(k-1);
  36. double p1=dp[i][j][k-1]*(i*j-(k-1))/t;
  37. double p2=dp[i-1][j][k-1]*(n-(i-1))*j/t;
  38. double p3=dp[i][j-1][k-1]*(m-(j-1))*i/t;
  39. double p4=dp[i-1][j-1][k-1]*(n-(i-1))*(m-(j-1))/t;
  40. dp[i][j][k]=p1+p2+p3+p4;
  41. }
  42. double ans=0;
  43. for(int i=max(n,m);i<=n*m;i++)
  44. ans+=i*(dp[n][m][i]-dp[n][m][i-1]);
  45. printf("%.12f\n",ans);
  46. }
  47. return 0;
  48. }

  题解:

LA 6972 Domination的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 2014牡丹江D Domination

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

  4. Mac Pro 使用 ll、la、l等ls的别名命令

    在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...

  5. Linux中的动态库和静态库(.a/.la/.so/.o)

    Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...

  6. Mac OS使用ll、la、l等ls的别名命令

    在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...

  7. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  8. zoj3822 Domination(概率dp)

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

  9. 获取在线人数 CNZZ 和 51.la

    string Cookies = string.Empty; /// <summary> /// 获取在线人数 (51.la统计器) /// </summary> /// &l ...

随机推荐

  1. 【bitset】Kth Minimum Clique

    #include<bits/stdc++.h> #define B bitset<105> using namespace std; typedef long long ll ...

  2. kube-dns和coreDNS的使用

    内部服务发现 前面我们给大家讲解了 Service 的用法,我们可以通过 Service 生成的 ClusterIP(VIP)来访问 Pod 提供的服务,但是在使用的时候还有一个问题:我们怎么知道某个 ...

  3. HTML form表单中action的正确写法

    我的Java Web Application的context是myweb,即http://localhost:8080/myweb/index.jsp是欢迎页. 现在我的一个Controller的映射 ...

  4. [Vue]vue-router的push和replace的区别

    1.this.$router.push() 描述:跳转到不同的url,但这个方法会向history栈添加一个记录,点击后退会返回到上一个页面. 2.this.$router.replace() 描述: ...

  5. 题解 P3369 【【模板】普通平衡树(Treap/SBT)】

    STL真是个好东西. 最近在看pb_ds库及vector和set的用法,就想用这三种操作来实现一下普通平衡树,结果pb_ds中的rbtree不支持重复值,而本蒟蒻也看不懂不懂各大佬用pb_ds的实现, ...

  6. docker启动 elasticsearch 修改 xmx xms 堆内存大小修改

    用docker 安装的elasticsearch 5.6版本默认堆内存最大设置的2G 可以通过如下方法修改 [root@nova-92 logs]# find /var/lib/docker/ -na ...

  7. spring boot 的一些高级用法

    1 spring boot 项目的创建 参考 https://www.cnblogs.com/PerZhu/p/10708809.html 2 首先我们先把Maven里面的配置完成 <depen ...

  8. RobHess的SIFT代码解析步骤三

    平台:win10 x64 +VS 2015专业版 +opencv-2.4.11 + gtk_-bundle_2.24.10_win32 主要参考:1.代码:RobHess的SIFT源码 2.书:王永明 ...

  9. 程序面试题——C实现

    平台:win10 x64 +VC6.0 2019/5/22 1.合并三个有序的链表 链表节点定义struct node{    int val;    struct node* next;}; str ...

  10. Window10下Python3.7的wordcloud库的安装与基本使用

    1.进入Python官网→点击Pypl→搜索“wordcloud”.如下图所示: 2.使用cmd安装,具体操作如下: 使用 pip list 查看是否安装成功