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

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

题目大意:有M个题目,T支队伍,第i个队伍做出第j个题目的概率为Pij,问每个队伍都至少做出1个题并且至少有一个队伍做出N题的概率。

先定义状态dp[i][j][k],代表第i支队伍从前j个题目里正好做出k题的概率。

有:dp[i][j][k] = dp[i][j-1][k]*(1-p[i][j]) + dp[i][j-1][k-1]*p[i][j];

然后设f[i]为前i支队伍里,每队至少做出一个题并且至少有一个队伍做出N题的概率。

那么f[i] = f[i-1]*(第i支队伍做出不少于1题的概率) + (1-f[i-1]-存在队伍没做出题的概率)*(第i支队伍做了不少于N题的概率)

上面这个是个全概率公式

于是乎:

 1 ///#pragma comment(linker, "/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <map>
 7 #include <set>
 8 #include <bitset>
 9 #include <cmath>
10 #include <numeric>
11 #include <iterator>
12 #include <iostream>
13 #include <cstdlib>
14 #include <functional>
15 #include <queue>
16 #include <stack>
17 #include <string>
18 #include <cctype>
19 using namespace std;
20 #define PB push_back
21 #define MP make_pair
22 #define SZ size()
23 #define ST begin()
24 #define ED end()
25 #define CLR clear()
26 #define ZERO(x) memset((x),0,sizeof(x))
27 typedef long long LL;
28 typedef unsigned long long ULL;
29 typedef pair<int,int> PII;
30 const double EPS = 1e-8;
31
32 const int MAX_T = 1111;
33 const int MAX_M = 33;
34
35 int M,T,N;
36 double p[MAX_T][MAX_M],f[MAX_T],any[MAX_T],dp[MAX_T][MAX_M][MAX_M];
37
38 int main(){
39     while( ~scanf("%d%d%d",&M,&T,&N), M!=0&&T!=0&&N!=0 ) {
40         ZERO(dp);
41         ZERO(f);
42         ZERO(any);
43         for(int i=1;i<=T;i++) {
44             for(int j=1;j<=M;j++) {
45                 scanf("%lf",&p[i][j]);
46             }
47         }
48         for(int i=1;i<=T;i++){
49             dp[i][0][0] = 1.0;
50             for(int j=1;j<=M;j++) {
51                 dp[i][j][0] = dp[i][j-1][0]*(1-p[i][j]);
52             }
53             for(int j=1;j<=M;j++){
54                 for(int k=1;k<=j;k++){
55                     dp[i][j][k] = dp[i][j-1][k]*(1-p[i][j]) + dp[i][j-1][k-1]*p[i][j];
56                 }
57             }
58             for(int j=1;j<=M;j++){
59                 for(int k=1;k<=M;k++){
60                     dp[i][j][k] += dp[i][j][k-1];
61                 }
62             }
63         }
64
65         f[0] = 0.0;
66         any[0] = 1.0;
67         for(int i=1;i<=T;i++){
68             any[i] = any[i-1]*(1.0-dp[i][M][0]);
69         }
70         for(int i=1;i<=T;i++){
71             any[i] = 1.0 - any[i];
72         }
73         any[0] = 0.0;
74
75         for(int i=1;i<=T;i++){
76             f[i] = f[i-1]*(dp[i][M][M]-dp[i][M][0]) + (1.0-f[i-1]-any[i-1])*(dp[i][M][M]-dp[i][M][N-1]);
77         }
78
79         printf("%.3f\n",f[T]);
80     }
81     return 0;
82 }
时间: 2024-07-29 02:02:47

[POJ2151]Check the difficulty of problems (概率dp)的相关文章

[poj2151]Check the difficulty of problems概率dp

解题关键:主要就是概率的推导以及至少的转化,至少的转化是需要有前提条件的. 转移方程:$dp[i][j][k] = dp[i][j - 1][k - 1]*p + dp[i][j - 1][k]*(1 - p)$ 其中$dp[i][j][k]$表示第$i$个人前j题恰好ac了$k$题.然后用前缀和处理一下最后的结果. 每队至少AC一题 反向考虑,用1-每队没A题的概率,再用乘法原理结合一下. 冠军队至少AC$n-1$题,也就是存在一支队伍AC数>=n-1,依然反向考虑,不过是在每队AC至少一题的

POJ 2151:Check the difficulty of problems 概率DP

Check the difficulty of problems 题目连接: http://poj.org/problem?id=2151 题意: 有M (0<M≤30)个人,和T (1<T≤1000)道题目,求所有人都至少做出了一道题且其中有人做出N (0<N≤M)道或N道以上的概率 题解: 求出满足条件1(所有人都至少做出一道题目)的概率,再求出满足条件1且所有人的题数都小于N道的概率,减一下就是答案了 代码 #include<stdio.h> #include<s

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

Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4748   Accepted: 2078 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp

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

题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 k 个题的概率,sum[i][j] 表示第 i 个队伍,做出 1-j 个题的概率,ans1等于, T个队伍,至少解出一个题的概率,ans2 表示T个队伍,至少解出一个题,但不超过N-1个题的概率,最后用ans1-ans2即可. 代码如下: #pragma comment(linker, "/STA

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

题目链接:http://poj.org/problem?id=2151 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following two terms: 1. All of the teams solv

POJ2151Check the difficulty of problems 概率DP

概率DP,还是有点恶心的哈,这道题目真是绕,问你T个队伍,m个题目,每个队伍做出哪道题的概率都给了,冠军队伍至少也解除n道题目,所有队伍都要出题,问你概率为多少? 一开始感觉是个二维的,然后推啊推啊没有推出来,一开始认为冠军队伍只能有一个,所以必须控制一个队伍解题数比其它队伍多,而且这个冠军队伍解题数必须大于等于n,大于n的时候其它队伍解题数就很难了,直到坑到最后才发现 原来可以很多队伍都是冠军,大家都是十道 那么大家都是冠军,---- 然后还是继续推二维,结果还是没想出,看来不是先假设方程才好

[POJ2151]Check the difficulty of problems(概率DP)

传送门 每个队之间是独立的 f[i][j]表示当前队伍前i个题答对j个的概率 满足条件的概率 == 全部方案(除去答对0)的概率 - 不满足条件的概率(每个队伍答对1~n-1) #include <cstdio> #include <cstring> #define N 101 int m, t, n; double sum, p1, p2, f[N][N]; int main() { int i, j, k; double x; while(~scanf("%d %d

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

题意:给出m.t.n,接着给出t行m列,表示第i个队伍解决第j题的概率. 现在让你求:每个队伍都至少解出1题,且解出题目最多的队伍至少要解出n道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的概率,减去所有队伍解出的题数在1~n-1之间的概率 这里关键是如何求出某个队伍解出的题数在1~n-1之间的概率,采用dp的方法: 用p(i,j)表示前i道题能解出j道的概率,有p(i,j)=p(i-1,j)*(1-p(i))+p(i-1,j-1)*p(i)p(i)表示解出第i题的概率. #inclu

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

Language: Default Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5419   Accepted: 2384 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the org