Poj 2151 check the difficulty of problems (DP, probability)

Source: Internet
Author: User

Link: poj 2151

Q: There are m questions in the competition, and t teams. PIJ indicates the probability that the I team will solve the J question,

Calculate the probability that each team should solve at least one question, and the champion army should solve at least N questions.

Analysis: the probability that each team should solve at least one question, and the champion army should solve at least N questions

Then the probability of the original request can be converted:

Probability of each team having at least one question P1 minus the probability of each team having a question between 1 and N-1 p2

Set DP [I] [J] [k] to indicate the probability that team I has solved K questions in the previous J questions.

DP [I] [J] [k] = DP [I] [J-1] [k-1] * PIJ + dp [I] [J-1] [k] * (1-pij)

Set sum [I] [J] to the probability that team I can solve the question J at most.

Sum [I] [J] = DP [I] [m] [0] + dp [I] [m] [1] +... + dp [I] [m] [J]

Sum [I] [m]-sum [I] [0] indicates the probability that team I should solve at least one question.

Sum [I] [N-1]-sum [I] [0] the probability of Team I solving the question [1, N-1]


#include<stdio.h>#include<string.h>double p[1005][32],dp[32][32],sum[32],p1,p2;int main(){    int t,m,n,i,j,k;    while(scanf("%d%d%d",&m,&t,&n)!=EOF){        if(t==0&&m==0&&n==0)            break;        for(i=1;i<=t;i++)            for(j=1;j<=m;j++)                scanf("%lf",&p[i][j]);        memset(dp,0,sizeof(dp));        memset(sum,0,sizeof(sum));        p1=p2=1.0;        for(i=1;i<=t;i++){            dp[0][0]=1.0;            for(j=1;j<=m;j++){                dp[j][0]=dp[j-1][0]*(1-p[i][j]);                for(k=1;k<=j;k++)                    dp[j][k]=dp[j-1][k]*(1-p[i][j])+dp[j-1][k-1]*p[i][j];            }            sum[0]=dp[m][0];            for(j=1;j<=m;j++)                sum[j]=sum[j-1]+dp[m][j];            p1*=(sum[m]-sum[0]);            p2*=(sum[n-1]-sum[0]);        }        printf("%.3lf\n",p1-p2);    }    return 0;}



Poj 2151 check the difficulty of problems (DP, probability)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.