0
点赞
收藏
分享

微信扫一扫

poj2151(概率dp)

求阙者 2022-08-31 阅读 93


要全部人都过1题而且至少有人过n题的概率。。

可以这么算,(1-全部人0题)*(1-全部人做了不多于n-1题(在无人做0题的前提下))

所以dp这块主要是算对每个人做了i题的概率而已,直接递推即可。。

然后被一个细节坑害了好久。。要是有一个人一题都做不出的话,那个条件概率的公式里面那个不做0题的概率作为分母是0。。然后会gg.... qaq

 

 

 

 

 

 

/**
*        ┏┓    ┏┓
*        ┏┛┗━━━━━━━┛┗━━━┓
*        ┃       ┃  
*        ┃   ━    ┃
*        ┃ >   < ┃
*        ┃       ┃
*        ┃... ⌒ ...  ┃
*        ┃       ┃
*        ┗━┓   ┏━┛
*          ┃   ┃ Code is far away from bug with the animal protecting          
*          ┃   ┃ 神兽保佑,代码无bug
*          ┃   ┃           
*          ┃   ┃       
*          ┃   ┃
*          ┃   ┃           
*          ┃   ┗━━━┓
*          ┃       ┣┓
*          ┃       ┏┛
*          ┗┓┓┏━┳┓┏┛
*           ┃┫┫ ┃┫┫
*           ┗┻┛ ┗┻┛
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 1005
#define nm 500005
#define pi 3.1415926535897931
using namespace std;
const ll inf=1000000000;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}











int n,m,p;
double a[NM][NM],ans,t,d[NM];
int main(){
//freopen("data.in","r",stdin);
while(m=read()){
n=read();p=read();ans=1;
inc(i,1,n)inc(j,1,m)scanf("%lf",&a[i][j]);
inc(i,1,n){
t=1;
inc(j,1,m)t*=1-a[i][j];
ans*=1-t;
}
t=1;
inc(i,1,n){
mem(d);d[0]=1;
inc(j,1,m){
dec(k,m,1)d[k]=d[k-1]*a[i][j]+d[k]*(1-a[i][j]);
d[0]*=1-a[i][j];
}
double tmp=0;
inc(j,1,p-1)tmp+=d[j];
if(tmp>0)tmp/=(1-d[0]);
t*=tmp;
}
ans*=1-t;
printf("%.3lf\n",ans);
}
return 0;
}

 

 

 

 

 

 

 

 

 

Check the difficulty of problems

Time Limit: 2000MS

 

Memory Limit: 65536K

Total Submissions: 8264

 

Accepted: 3534

 

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 solve at least one problem.
2. The champion (One of those teams that solve the most problems) solves at least a certain number of problems.

Now the organizer has studied out the contest problems, and through the result of preliminary contest, the organizer can estimate the probability that a certain team can successfully solve a certain problem.

Given the number of contest problems M, the number of teams T, and the number of problems N that the organizer expect the champion solve at least. We also assume that team i solves problem j with the probability Pij (1 <= i <= T, 1<= j <= M). Well, can you calculate the probability that all of the teams solve at least one problem, and at the same time the champion team solves at least N problems?

Input

The input consists of several test cases. The first line of each test case contains three integers M (0 < M <= 30), T (1 < T <= 1000) and N (0 < N <= M). Each of the following T lines contains M floating-point numbers in the range of [0,1]. In these T lines, the j-th number in the i-th line is just Pij. A test case of M = T = N = 0 indicates the end of input, and should not be processed.

Output

For each test case, please output the answer in a separate line. The result should be rounded to three digits after the decimal point.

Sample Input

2 2 2
0.9 0.9
1 0.9
0 0 0

Sample Output

0.972

Source

​​POJ Monthly​​,鲁小石

[​​Submit​​​]   [Go Back]   [​​Status​​​]   [​​Discuss​​]

 

举报

相关推荐

0 条评论