MWC '15 #1 P4: Genetic Probability

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 3.0s
Memory limit: 256M

Author:
Problem type

aurpine is learning about genetics in biology class. More specifically, he is learning about determining the traits of a possible offspring given the traits of its parents. He spends his days trying to determine the genetic traits of his future children. Sadly, aurpine is not very good at biology so he has asked you, his studious best friend, to calculate the probability of him having a child that looks a specific way, given the genetic details of him and his future bride!

To determine the traits of an offspring, you must find a combination of the genetic code of both parents.

In biology, traits are determined by parts of a chromosome called alleles. Alleles come in pairs, the combinations of these pairs give each person certain traits. The combination of these traits is called a genotype. Alleles can hold either dominant or recessive traits. Dominant traits are represented by capital letters whereas their recessive counterparts are denoted by a lowercase letter.

For example:

Genotype of Parent 1: AaBb

Genotype of Parent 2: AaBb

A - Dominant trait, a - recessive trait

B - Dominant trait 2, b - recessive trait 2

Possible Offspring: AABB, AABb, AAbb, AaBB, AaBb, Aabb, aaBB, aaBb, aabb

To find possible combinations of each trait, the 2 alleles from the first parent are split and combined with the 2 alleles of the trait from the second parent like so:

Given the genotype of 2 parents and the genotype of an offspring, output the probability of the parents creating an offspring with the specified genotype.

Assume that both parents and their offspring will have genotypes number of traits, N.

Input Specification

The first line of input will contain one integer, N.

The next 3 lines will contain the genotype of the parents and their offspring. These genotypes will all be strings of length 2N composed of latin letters.

Note: Fast input may be required.

Subtask 1 [20%]

1 \le N \le 10

Subtask 2 [30%]

1 \le N \le 5 \cdot 10^3

Subtask 3 [50%]

1 \le N \le 5 \cdot 10^6

Output Specification

Output the probability of the two parents producing the specified offspring precise to 6 decimal places.

Sample Input

2
AaBb
AaBB
aaBB

Sample Output

0.125000

Explanation of Sample

The possible offspring genotypes of the two parents are:

Cross:
AaBb × AaBB
× AB Ab aB ab
AB AABB AAbB aABB aAbB
AB AABB AAbB aABB aAbB
aB AaBB AabB aaBB aabB
aB AaBB AabB aaBB aabB

Of the 16 possibilities, 2 of them match the given genotype, therefore the probability of creating that specific offspring is 2/16 = 0.125000.


Comments


  • 0
    nathanl3  commented on March 16, 2016, 2:13 a.m.

    Does it loop back to 'aA'?


    • 1
      Hypnova  commented on March 18, 2016, 1:33 a.m.

      The letters of the traits don't really matter