题目链接:http://poj.org/problem?id=2151

题意:

  一次ACM比赛,有t支队伍,比赛共m道题。

  第i支队伍做出第j道题的概率为p[i][j].

  问你所有队伍都至少做出一道,并且有队伍做出至少n道的概率。

题解:

  关于【至少】问题的表示。

  

  对于每一支队伍:

    mst[i][j] = P(第i支队伍做出至多j道题)

    则 P(第i支队伍做出至少j道题) = 1 - mst[i][j-1]

  

  对于所有队伍:

    P(所有队伍至少答出一题) = ∏ (1 - mst[i][0])

    P(所有队伍答题数在1到n-1) = ∏ (mst[i][n-1] - mst[i][0])

    所以答案:

    P(所有队伍至少答出一题,且有队伍做出至少n道) = P(所有队伍至少答出一题) - P(所有队伍答题数在1到n-1)

  所以求mst数组好啦~~~

  dp[i][j][k] = probability

  i:第i支队伍

  j:考虑到前j道题(包含j)

  k:恰好做出k道

  所以 mst[i][j] = sigma(dp[i][m][0 to j])

  怎么求dp数组呢:

    转移:dp[i][j][k] = dp[i][j-1][k-1]*p[i][j] + dp[i][j-1][k]*(1-p[i][j])

    边界:dp[i][0][0] = 1, others = 0

  所以这道题:先求dp,再求mst,最后统计ans。

AC Code:

  1. // state expression:
  2. // dp[i][j][k] = probability
  3. // i: ith team
  4. // j: jth question and before
  5. // k: solved k questions
  6. // mst[i][j]
  7. // i: ith team
  8. // j: all the teams solved at most j questions
  9. //
  10. // find the answer:
  11. // P(all 1 to m) - P(all 1 to n-1)
  12. //
  13. // transferring:
  14. // dp[i][j][k] = dp[i][j-1][k-1]*p[i][j] + dp[i][j-1][k]*(1-p[i][j])
  15. //
  16. // boundary:
  17. // dp[i][0][0] = 1
  18. // others = 0
  19. //
  20. // calculate:
  21. // mst[i][j] = sigma dp[i][m][0 to j]
  22. // P1 = pi (1 - mst[i][0])
  23. // P2 = pi (mst[i][n-1] - mst[i][0])
  24. //
  25. // step:
  26. // 1) cal dp
  27. // 2) cal mst
  28. // 3) cal ans
  29. #include <iostream>
  30. #include <stdio.h>
  31. #include <string.h>
  32. #define MAX_T 1005
  33. #define MAX_N 35
  34. #define MAX_M 35
  35.  
  36. using namespace std;
  37.  
  38. int n,m,t;
  39. double p1,p2;
  40. double p[MAX_T][MAX_M];
  41. double dp[MAX_T][MAX_M][MAX_M];
  42. double mst[MAX_T][MAX_M];
  43.  
  44. void read()
  45. {
  46. for(int i=;i<=t;i++)
  47. {
  48. for(int j=;j<=m;j++)
  49. {
  50. cin>>p[i][j];
  51. }
  52. }
  53. }
  54.  
  55. void cal_dp()
  56. {
  57. memset(dp,,sizeof(dp));
  58. for(int i=;i<=t;i++)
  59. {
  60. dp[i][][]=;
  61. for(int j=;j<=m;j++)
  62. {
  63. for(int k=;k<=m;k++)
  64. {
  65. if(k->=) dp[i][j][k]+=dp[i][j-][k-]*p[i][j];
  66. dp[i][j][k]+=dp[i][j-][k]*(-p[i][j]);
  67. }
  68. }
  69. }
  70. }
  71.  
  72. void cal_mst()
  73. {
  74. // mst[i][j] = sigma dp[i][m][0 to j]
  75. memset(mst,,sizeof(mst));
  76. for(int i=;i<=t;i++)
  77. {
  78. for(int j=;j<=m;j++)
  79. {
  80. for(int k=;k<=j;k++)
  81. {
  82. mst[i][j]+=dp[i][m][k];
  83. }
  84. }
  85. }
  86. }
  87.  
  88. void cal_ans()
  89. {
  90. // P1 = pi (1 - mst[i][0])
  91. // P2 = pi (mst[i][n-1] - mst[i][0])
  92. p1=1.0;
  93. p2=1.0;
  94. for(int i=;i<=t;i++)
  95. {
  96. p1*=(-mst[i][]);
  97. p2*=(mst[i][n-]-mst[i][]);
  98. }
  99. }
  100.  
  101. void solve()
  102. {
  103. cal_dp();
  104. cal_mst();
  105. cal_ans();
  106. }
  107.  
  108. void print()
  109. {
  110. printf("%.3f\n",p1-p2);
  111. }
  112.  
  113. int main()
  114. {
  115. while(cin>>m>>t>>n)
  116. {
  117. if(m== && t== && n==) break;
  118. read();
  119. solve();
  120. print();
  121. }
  122. }

POJ 2151 Check the difficulty of problems:概率dp【至少】的更多相关文章

  1. POJ 2151 Check the difficulty of problems 概率dp+01背包

    题目链接: http://poj.org/problem?id=2151 Check the difficulty of problems Time Limit: 2000MSMemory Limit ...

  2. [ACM] POJ 2151 Check the difficulty of problems (概率+DP)

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4748   ...

  3. POJ 2151 Check the difficulty of problems (概率DP)

    题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...

  4. POJ 2151 Check the difficulty of problems (动态规划-可能DP)

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4522   ...

  5. POJ 2151 Check the difficulty of problems

    以前做过的题目了....补集+DP        Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K ...

  6. poj 2151 Check the difficulty of problems(概率dp)

    poj double 就得交c++,我交G++错了一次 题目:http://poj.org/problem?id=2151 题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 问 ...

  7. POJ 2151 Check the difficulty of problems (概率dp)

    题意:给出m.t.n,接着给出t行m列,表示第i个队伍解决第j题的概率. 现在让你求:每个队伍都至少解出1题,且解出题目最多的队伍至少要解出n道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的 ...

  8. [POJ2151]Check the difficulty of problems (概率dp)

    题目链接:http://poj.org/problem?id=2151 题目大意:有M个题目,T支队伍,第i个队伍做出第j个题目的概率为Pij,问每个队伍都至少做出1个题并且至少有一个队伍做出N题的概 ...

  9. POJ2157 Check the difficulty of problems 概率DP

    http://poj.org/problem?id=2151   题意 :t个队伍m道题,i队写对j题的概率为pij.冠军是解题数超过n的解题数最多的队伍之一,求满足有冠军且其他队伍解题数都大于等于1 ...

随机推荐

  1. Linux的经常使用命令(2) - 关机

    关机命令 shutdown‑h now 马上进行关机 shutdown‑r now 如今又一次启动计算机 -t sec : -t后面加秒数,即"过几秒后关机" -k      : ...

  2. 【Linux】线程并发拷贝程序

    据说大连某211高校的李教授越来越重口.不仅延续要求他所带的每个本科班.都要写一份线程并发拷贝程序的传统,并且还開始规定不能用Java语言写作.导致我之前写的<[Java]线程并发拷贝程序> ...

  3. java中 ExecutorService,Executor,ThreadPoolExecutor的用法

    package com; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Executor; import ...

  4. linux下ejabberd框架搭建

    ejabberd为erlang的IM的开源框架,一直想找个时间研究研究: 1.下载Ejabberd安装包 wget http://www.process-one.net/downloads/ejabb ...

  5. 短信计时器Utils

    package com.lvshandian.partylive.utils; import android.content.Context;import android.os.CountDownTi ...

  6. tp框架知识 之(链接数据库和操作数据内容)

    框架有时会用到数据库的内容,在"ThinkPhp框架知识"的那篇随笔中提到过,现在这篇随笔详细的描述下. 一.链接数据库 (1)找到模块文件夹中的Conf文件夹,然后进行编写con ...

  7. Win10上Python3通过pip安装时出现UnicodeDecodeError

    http://blog.csdn.net/qq_33530388/article/details/68933201 解决方法: 打开 c:\program files\python36\lib\sit ...

  8. Paxos is Simple

    [角色]0-MainProposer提案生成者1-提案发送者(MainProposer+OtherProposer)2-提案接收者(Acceptor)[动作]0-MainProposer----> ...

  9. iframe式ajax调用

    1.新建 a.html <!doctype html> <html> <head> <meta charset='utf-8'> <title&g ...

  10. Python爬虫--Urllib库

    Urllib库 Urllib是python内置的HTTP请求库,包括以下模块:urllib.request (请求模块).urllib.error( 异常处理模块).urllib.parse (url ...