Introduction to Mendelian Inheritance

Modern laws of inheritance were first described by Gregor Mendel (an Augustinian Friar) in 1865. The contemporary hereditary model, called blending inheritance, stated that an organism must exhibit a blend of its parent’s traits. This rule is obviously violated both empirically (consider the huge number of people who are taller than both their parents) and statistically (over time, blended traits would simply blend into the average, severely limiting variation).
Mendel, working with thousands of pea plants, believed that rather than viewing traits as continuous processes, they should instead be divided into discrete building blocks called factors. Furthermore, he proposed that every factor possesses distinct forms, called alleles.
In what has come to be known as his first law (also known as the law of segregation), Mendel stated that every organism possesses a pair of alleles for a given factor. If an individual’s two alleles for a given factor are the same, then it is homozygous for the factor; if the alleles differ, then the individual is heterozygous. The first law concludes that for any factor, an organism randomly passes one of its two alleles to each offspring, so that an individual receives one allele from each parent.
Mendel also believed that any factor corresponds to only two possible alleles, the dominant and recessive alleles. An organism only needs to possess one copy of the dominant allele to display the trait represented by the dominant allele. In other words, the only way that an organism can display a trait encoded by a recessive allele is if the individual is homozygous recessive for that factor.
We may encode the dominant allele of a factor by a capital letter (e.g., AA) and the recessive allele by a lower case letter (e.g., aa). Because a heterozygous organism can possess a recessive allele without displaying the recessive form of the trait, we henceforth define an organism’s genotype to be its precise genetic makeup and its phenotype as the physical manifestation of its underlying traits.
The different possibilities describing an individual’s inheritance of two alleles from its parents can be represented by a Punnett square; see Figure 1 for an example.

Mendel's First Law - 图1 Figure 1. A Punnett square representing the possible outcomes of crossing a heterozygous organism (Yy) with a homozygous recessive organism (yy); here, the dominant allele Y corresponds to yellow pea pods, and the recessive allele y corresponds to green pea pods.

Problem

image.png

Solution

题意讲孟德尔遗传第一定律,然后问题是随机无放回抽样,基本都是高中知识。给定数据意思就是从 Mendel's First Law - 图3 个显性纯合 AAMendel's First Law - 图4 个杂合个体 AaMendel's First Law - 图5 个纯合隐性个体 aa 中,进行随机抽取两人(抽完第一人不放回),那么产生其后代产生显性性状( AA, Aa )的概率为多少?
注意:题目肯定大于等于 2

方法一、暴力模拟法

  1. 随机抽样且不放回:第一次抽完后,总人数就减少一人,所有之后再抽就会倒置概率变化
  2. 抽什么样的个体才会让子代产生显性性状呢?
    1. 第一次抽 AAMendel's First Law - 图6
      • 第二次抽 AA,,则后代是显性性状概率为 Mendel's First Law - 图7
      • 第二次抽 AaMendel's First Law - 图8,则后代是显性性状概率为 Mendel's First Law - 图9
      • 第二次抽 aaMendel's First Law - 图10,则后代是显性性状概率为 Mendel's First Law - 图11
    2. 第一次抽 AaMendel's First Law - 图12
      • 第二次抽 AAMendel's First Law - 图13,则后代是显性性状概率为 Mendel's First Law - 图14
      • 第二次抽 AaMendel's First Law - 图15,则后代是显性性状概率为 Mendel's First Law - 图16
      • 第二次抽 aaMendel's First Law - 图17,则后代是显性性状概率为 Mendel's First Law - 图18
    3. 第一次抽 aaMendel's First Law - 图19
      • 第二次抽 AAMendel's First Law - 图20,则后代是显性性状概率为 Mendel's First Law - 图21
      • 第二次抽 AaMendel's First Law - 图22,则后代是显性性状概率为 Mendel's First Law - 图23
      • 第二次抽 aaMendel's First Law - 图24,则后代是显性性状概率为 Mendel's First Law - 图25

综上:就是枚举第一次和第二次抽样的顺序然后概率结果相加即可。我们还可以简化上面的 9 个判断!

  1. 当任一次抽到都是显性纯合,则此轮一定产生显性性状后代!
  2. 计算 正反交的组合概率即可。 ```python class Solution: def dominantProbilities(self, k: int, m: int, n: int) -> str:
    1. tot = k + m + n
    2. d = {'AA': k, 'Aa': m, 'aa': n}
    3. p = 0.0
    4. for first in d:
    5. p1 = d[first] / tot
    6. d[first] -= 1 # 此处表示不放回抽样
    7. for second in d:
    8. p2 = d[second] / (tot - 1)
    9. if first == 'AA' or second == 'AA':
    10. p += p1 * p2
    11. elif first == 'Aa' and second == 'Aa':
    12. p += p1 * p2 * 3 / 4
    13. elif {first, second} == {'Aa', 'aa'}:
    14. p += p1 * p2 * 1 / 2
    15. d[first] += 1 # 此处表示不选它
    16. return f'{p:.5}' # 保留五位小数

k, m, n = map(int, input().split()) # 2 2 2 print(Solution().dominantProbilities(k, m, n)) # 0.78333

  1. <a name="Eo6zx"></a>
  2. ### 方法二、数学法
  3. 同抽样问题,我们倒过来算隐性性状的概率是多少。
  4. ```python
  5. class Solution:
  6. def dominantProbilities(self, k: int, m: int, n: int) -> str:
  7. tot = m + n + k
  8. Aa2Aa = (m / tot) * ((m - 1) / (tot - 1)) / 4 # 1/4:aa
  9. Aa2aa = (m / tot) * (n / (tot - 1)) / 2 # 1/2:aa
  10. aa2Aa = (n / tot) * (m / (tot - 1)) / 2 # 1/2:aa
  11. aa2aa = (n / tot) * ((n - 1) / (tot - 1)) # 1/1:aa
  12. return f'{1 - (Aa2Aa + Aa2aa + aa2aa + aa2Aa):.5}' # .5f
  13. k, m, n = map(int, input().split()) # 2 2 2
  14. print(Solution().dominantProbilities(k, m, n)) # 0.78333