POJ 2151 Check The difficulty of problems

Source: Internet
Author: User

Probability, $DP $.

People are independent, can first calculate each person in $m$ problem to make $0$ problem, $1$ problem ... $m the probability of the problem. This DP push can be counted.

Set $dp[i][j][k]$ to indicate the probability that the first $i$ person in the first $j$ question, to make the $k$ problem. $DP [i][j][k]=p[i][j]*dp[i][j-1][k-1]+ (1-p[i][j]) *dp[i][j-1][k]$.

If everyone has the probability that the problem is $p1$, everyone has a problem, and each person's question is $1$ to the $n-1$ between the probability of $p2$; then the answer is $p1-p2$, and $p1$, $P 2$ can be calculated directly according to $dp$ results.

#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-6;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} Template<classT>inlinevoidRead (T &x) {    Charc =GetChar (); X=0;  while(!isdigit (c)) C =GetChar ();  while(IsDigit (c)) {x= x *Ten+ C-'0'; C=GetChar (); }}intM,t,n;Doublep[1005][ *],dp[1005][ *][ *];intMain () { while(~SCANF ("%d%d%d",&m,&t,&N)) {if(m==0&&t==0&&n==0) Break;  for(intI=1; i<=t;i++)             for(intj=1; j<=m;j++) scanf ("%LF",&P[i][j]); Memset (DP,0,sizeofDP);  for(intI=1; i<=t;i++) {dp[i][0][0]=1;  for(intj=1; j<=m;j++) dp[i][j][0]=dp[i][j-1][0]*(1-P[i][j]);  for(intj=1; j<=m;j++)                 for(intk=1; k<=j;k++) Dp[i][j][k]=p[i][j]*dp[i][j-1][k-1]+(1-P[I][J]) *dp[i][j-1][k]; //for (int j=0;j<=m;j++) printf ("%lf", Dp[i][m][j]); //printf ("\ n");        }        Doublep1=1, p2=1;  for(intI=1; i<=t;i++)        {            Doublesum=0;  for(intj=1; j<n;j++) sum=sum+Dp[i][m][j]; P2=p2*sum;  for(intj=n;j<=m;j++) sum=sum+Dp[i][m][j]; P1=p1*sum; } printf ("%.3f\n", p1-p2); }    return 0;}

POJ 2151 Check The difficulty of problems

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.