Description
Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following S:
-All of the teams solve at least one problem.
-the champion (one of those teams that solve the most problems) solves at least a certain number of problems.
Now the organizer have studied out the contest problems, and through the result of preliminary contest, the organizer Can estimate the probability that a certain team can successfully solve a certain problem.
Given the number of contest problems M, the number of teams T, and the number of problems N that the organizer expect The champion solve at least. We also assume that team I solves problem J with the probability Pij (1 <= i <= T, 1<= J <= M). Well, can-calculate the probability, all of the teams solve at least one problem, and at the same time the Champio N team solves at least n problems?
Test Instructions
There are M-m questions, T-T teams, give all teams the probability of solving each problem separately Pij P_{ij}, ask each team to solve at least 1 questions and the championship team to solve the probability of at least n N.
parsing
Involve at least this word, you might as well use some prefixes and tricks.
Assuming P1 p1 is the probability that all teams can solve up to M m, p2 P2 is the probability that all teams will solve the problem of up to n−1 N-1, then the final answer is P1−P2 p1-p2.
We need to calculate each team's contribution separately, and then multiply the corresponding answers to calculate P1 p1, p2 p2.
Set F[i][j] F[i][j] represents the current problem of the first I I, solved the probability of a total J-J problem. It is not difficult to find the transfer equation
F[i][j]=f[i−1][j−1]xp[i][j]+f[i−1][j]x (1−p[i][j]) f[i][j] = F[i-1][j-1] \times p[i][j] + f[i-1][j] \times (1-p[i][j])
Then use Sum[i] sum[i to represent the probability of solving the problem of up to I I in all problems, in fact, is the prefix and.
So the team for P1 P1 contribution is sum[m]−sum[0] sum[m]-sum[0], p2 P2 contribution is sum[n−1]−sum[0] sum[n-1]-sum[0].
array can roll, you don't have to roll it's okay
#include <iostream> #include <cstdio> #include <cstdlib> #include < cstring> #include <map> #include <vector> #include <cmath> #include <queue> #include < stack> #include <algorithm> #include <cctype&