其他分享
首页 > 其他分享> > POJ2151Check the difficulty of problems

POJ2151Check the difficulty of problems

作者:互联网

 题目: 概率dp||组合数学;

 

http://poj.org/problem?id=2151

 

一套题,有T个题,M个人应考,已知每个人做来某题的概率。问X的概率。X满足,每个考生至少做来一道题。至少有一人做的题不少于N道

思路:
p[i][j][k] 表示第i个考试前j个题会做k道的概率。再根据题意进行DP。
p[i][j][k] = p[i][j-1][k]*(1-a[i][j]) + p[i][j-1][k-1]*a[i][j];

然后用 每个人至少做出一道题的概率,减去 每个人至少做一道,至多做n-1道的概率; just answer。

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#define LL long long
#define ULL unsigned long long
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define dep(i,j,k) for(int i=k;i>=j;i--)
#define INF 0x3f3f3f3f
#define mem(i,j) memset(i,j,sizeof(i))
#define make(i,j) make_pair(i,j)
#define pb push_back
using namespace std;
double p[1010][32][32],P1,P2,a[1010][32],tmp,res;
int main()
{
    int i,j,k,m,n,t;
    while(~scanf("%d%d%d",&m,&t,&n)){//t人 m题
        if(m==0&&t==0&&n==0) return 0;
        memset(p,0,sizeof(p));
        for(i=1;i<=t;i++)
         for(j=1;j<=m;j++)
           scanf("%lf",&a[i][j]);
        for(i=1;i<=t;i++)
         for(j=0;j<=m;j++)
          for(k=0;k<=j;k++){
               if(j==0&&k==0) p[i][j][k]=1;
               else if(j==k)  p[i][j][k]=p[i][j-1][k-1]*a[i][j];
               else if(k==0)  p[i][j][k]=p[i][j-1][k]*(1-a[i][j]);
               else p[i][j][k]=p[i][j-1][k-1]*a[i][j]+p[i][j-1][k]*(1-a[i][j]);
          }
        res=1;P1=1;
        for(i=1;i<=t;i++){
            P1*=(1-p[i][m][0]);
            tmp=0;
            for(j=1;j<n;j++) tmp+=p[i][m][j];
            res*=tmp;
        }
        res=P1-res;
        printf("%.3f\n",res); 
    }  return 0;
}
View Code

 

参考:https://www.cnblogs.com/hua-dong/p/8044969.html

 

标签:概率,POJ2151Check,int,32,problems,long,difficulty,include,define
来源: https://www.cnblogs.com/Willems/p/10946176.html