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.

Author: d

The N 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 N probabilities to get the answer. Therefore, if you can solve N=1, then you should be able to solve the entire problem.

Let's solve N=1. The parents will produce these 4 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 1/4.
  • Aa with probability 1/2. Remember that aA is the same as Aa.
  • aa with probability 1/4.

Your code must handle all combinations of traits. Each of the 3 traits could be AA, Aa, or aa. Also, the probability must be one of \{0, 1/4, 1/2, 1\}.

Time complexity: \mathcal O(N). There are N traits and each trait takes \mathcal O(1).


Comments

There are no comments at the moment.