Editorial for MWC '15 #1 P4: Genetic Probability
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
The traits are independent of each other. For each trait, calculate the probability that the parents will produce the offspring's trait. Afterwards, multiply together the probabilities to get the answer. Therefore, if you can solve , then you should be able to solve the entire problem.
Let's solve . The parents will produce these traits with equal probability:
- Parent 1's first allele + Parent 2's first allele
- Parent 1's first allele + Parent 2's second allele
- Parent 1's second allele + Parent 2's first allele
- Parent 1's second allele + Parent 2's second allele
For example, if the parents' traits are Aa
and Aa
, then the offspring's trait will be:
AA
with probability .Aa
with probability . Remember thataA
is the same asAa
.aa
with probability .
Your code must handle all combinations of traits. Each of the traits could be AA
, Aa
, or aa
. Also, the probability must be one of .
Time complexity: . There are traits and each trait takes .
Comments