1) poj-2151-probability dp

Source: Internet
Author: User

Question:

Give you m, t, n, representing t team, do m questions, for all teams, all do one or more questions, and at least one team has the probability of doing n questions.

Practice:

P [I] [j] indicates the probability that the I-th team will answer the j-th question.

Dp [I] [j] [k] represents the I-th team, and the probability that the first j questions will have k questions.

The probability bans * = (1-dp [I] [m] [0]) of all teams on one or more questions // the product of the probability that a team on the other has on the other.

When the probability that all teams have one or more questions:

At least one team has the probability to do n to the question = the probability that all teams have the right to one question-the probability that all teams have the right to less than n questions.

Code:


[Html]
# Include <stdio. h>
# Include <iostream>
# Include <string. h>
# Include <algorithm>
# Include <queue>
# Include <stack>
# Include <map>
# Include <string>
# Include <stdlib. h>
# Define INF_MAX 0x7fffffff
# Define INF 999999
# Define max3 (a, B, c) (max (a, B)> c? Max (a, B): c)
# Define min3 (a, B, c) (min (a, B) <c? Min (a, B): c)
# Define mem (a, B) memset (a, B, sizeof ())
Using namespace std;
Struct node
{
Int u;
Int v;
Int w;
Bool friend operator <(node a, node B ){
Return a. w <B. w;
}
} Edge [2, 1001];
Int gcd (int n, int m) {if (n <m) swap (n, m); return n % m = 0? M: gcd (m, n % m );}
Int lcm (int n, int m) {if (n <m) swap (n, m); return n/gcd (n, m) * m ;}
Double p [1, 1001] [51];
Double dp [1, 1001] [31] [31];
Int main ()
{
 
Int m, t, n, I, j, k;
While (scanf ("% d", & m, & t, & n) & (m | n | t ))
{
For (I = 1; I <= t; I ++)
{
For (j = 1; j <= m; j ++)
{
Scanf ("% lf", & p [I] [j]);
}
}
For (I = 1; I <= t; I ++)
{
Dp [I] [0] [0] = 1;
For (j = 1; j <= m; j ++)
{
Dp [I] [0] [j] = 0;
}
}
For (I = 1; I <= t; I ++)
{
For (j = 1; j <= m; j ++)
{
Dp [I] [j] [0] = dp [I] [J-1] [0] * (1-p [I] [j]);
For (k = 1; k <= j; k ++)
{
Dp [I] [j] [k] = dp [I] [J-1] [k] * (1-p [I] [j]) + dp [I] [J-1] [k-1] * p [I] [j];
}
}
}
Double bans; // The probability that all people do the same for one or more questions
Bans = 1;
For (I = 1; I <= t; I ++)
{
Bans * = (1-dp [I] [m] [0]);
}
Double ans; // at least one person has the probability of doing n questions
Ans = 1;
For (I = 1; I <= t; I ++)
{
Double ks;
Ks = 0;
For (j = 1; j <n; j ++)
{
Ks + = dp [I] [m] [j];
}
Ans * = ks;
}
Ans = bans-ans;
Printf ("%. 3f \ n", ans );
}
Return 0;
}

# Include <stdio. h>
# Include <iostream>
# Include <string. h>
# Include <algorithm>
# Include <queue>
# Include <stack>
# Include <map>
# Include <string>
# Include <stdlib. h>
# Define INF_MAX 0x7fffffff
# Define INF 999999
# Define max3 (a, B, c) (max (a, B)> c? Max (a, B): c)
# Define min3 (a, B, c) (min (a, B) <c? Min (a, B): c)
# Define mem (a, B) memset (a, B, sizeof ())
Using namespace std;
Struct node
{
Int u;
Int v;
Int w;
Bool friend operator <(node a, node B ){
Return a. w <B. w;
}
} Edge [2, 1001];
Int gcd (int n, int m) {if (n <m) swap (n, m); return n % m = 0? M: gcd (m, n % m );}
Int lcm (int n, int m) {if (n <m) swap (n, m); return n/gcd (n, m) * m ;}
Double p [1, 1001] [51];
Double dp [1, 1001] [31] [31];
Int main ()
{

Int m, t, n, I, j, k;
While (scanf ("% d", & m, & t, & n) & (m | n | t ))
{
For (I = 1; I <= t; I ++)
{
For (j = 1; j <= m; j ++)
{
Scanf ("% lf", & p [I] [j]);
}
}
For (I = 1; I <= t; I ++)
{
Dp [I] [0] [0] = 1;
For (j = 1; j <= m; j ++)
{
Dp [I] [0] [j] = 0;
}
}
For (I = 1; I <= t; I ++)
{
For (j = 1; j <= m; j ++)
{
Dp [I] [j] [0] = dp [I] [J-1] [0] * (1-p [I] [j]);
For (k = 1; k <= j; k ++)
{
Dp [I] [j] [k] = dp [I] [J-1] [k] * (1-p [I] [j]) + dp [I] [J-1] [k-1] * p [I] [j];
}
}
}
Double bans; // The probability that all people do the same for one or more questions
Bans = 1;
For (I = 1; I <= t; I ++)
{
Bans * = (1-dp [I] [m] [0]);
}
Double ans; // at least one person has the probability of doing n questions
Ans = 1;
For (I = 1; I <= t; I ++)
{
Double ks;
Ks = 0;
For (j = 1; j <n; j ++)
{
Ks + = dp [I] [m] [j];
}
Ans * = ks;
}
Ans = bans-ans;
Printf ("%. 3f \ n", ans );
}
Return 0;
}

 

 

 

 

 

 


 

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.