Poj 2151 check the difficulty of problems (check the difficulty of the problem)

Source: Internet
Author: User

Poj 2151 check the difficulty of problems

Http://poj.org/problem? Id = 2151

Question: at this moment, there are tn questions and DN teams, who know the probability that each team can answer each question. Q: The champion should at least answer n (1 <= n <= Tn) the probability that other teams should answer at least one question

DP + Probability

Method:

F [I] [J] probability of Team I to answer question J

G [I] [J] [k] probability that the first J question of Team I will be used to answer K questions

State transition equation: G [I] [J] [k] = G [I] [J-1] [k-1] * f [I] [J] + G [I] [J-1] [k] * (1-F [I] [J])

 

1/* 2 problem: 2151 User: bibier 3 memory: 5120 K time: 47 Ms 4 Language: G ++ result: accepted 5 */6 7 # include <stdio. h> 8 # include <string. h> 9 # include <iostream> 10 # include <algorithm> 11 # include <cstdio> 12 # include <cstring> 13 # include <cmath> 14 # include <stack> 15 # include <queue> 16 # include <vector> 17 using namespace STD; 18 # define M 0x0f0f0f19 # define min (A, B) (A> B? B: a) 20 # define max (A, B) (A> B? A: B) 21 22 23 float f [1003] [33]; // F [I] [J] the probability that team I performs the J question 24 float G [1003] [33] [33]; // G [I] [J] [k] the probability that the first J question of Team I has a K question is 25 26 // G [I] [J] [k] = G [I] [J-1] [k-1] * f [I] [J] + G [I] [J-1] [k] * (1-F [I] [J]) 27 int main () 28 {29 int TN, dn, N; 30 int I, j, k; 31 While (scanf ("% d", & TN, & DN, & N )! = EOF) 32 {33 If (Tn = 0 & DN = 0 & n = 0) 34 break; 35 memset (G, 0, sizeof (g); 36 memset (F, 0, sizeof (f); 37 38 for (I = 1; I <= DN; I ++) 39 For (j = 1; j <= tn; j ++) 40 scanf ("% F", & F [I] [J]); 41 42 for (I = 1; I <= DN; I ++) 43 {44g [I] [1] [0] = 1-F [I] [1]; 45g [I] [1] [1] = f [I] [1]; 46} 47 48 for (I = 1; I <= DN; I ++) 49 for (j = 2; j <= tn; j ++) 50 for (k = 0; k <= J; k ++) 51 {52 If (k = J) 53g [I] [J] [k] = G [I] [J-1] [k-1] * f [I] [J]; 54 else if (k = 0) 55g [I] [J] [k] = G [I] [J-1] [k] * (1-F [I] [J]); 56 else57 G [I] [J] [k] = G [I] [J-1] [k-1] * f [I] [J] + G [I] [J-1] [k] * (1-F [I] [J]); 58} 59 float all = 1; 60 for (I = 1; I <= DN; I ++) // The final probability for each team to do at least one question is 61 all * = (1-g [I] [tn] [0]); 62 63 float midall = 1; 64 for (I = 1; I <= DN; I ++) 65 {66 float everyd = 0; 67 for (j = 1; j <n; j ++) 68 {69 everyd + = G [I] [tn] [J]; 70} 71 midall * = everyd; 72} 73 all-= midall; 74 printf ("%. 3f \ n ", all); 75} 76 return 0; 77}
View code

 

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.