1. 程式人生 > 其它 >Rosalind第41題:Maximum Matchings and RNA Secondary Structures

Rosalind第41題:Maximum Matchings and RNA Secondary Structures

技術標籤:控制科學與工程python

Problem

Figure 1.The bonding graph of s = UAGCGUGAUCAC (left) has a perfect matching of basepair edges, but this is not the case for t = CAGCGUGAUCAC (right), in which one symbol has been replaced.

Figure 2.A maximum matching (highlighted in red) is shown in each of the three graphs above. You can verify that no other matching can contain more edges. (Courtesy: Miym, Wikimedia Commons User)

Figure 3.A red maximum matching of basepair edges in the bonding graph for t = CAGCGUGAUCAC.

Thegraph theoreticalanalogue of the quandary stated in the introduction above is that if we have anRNA stringthat does not have the same number of occurrences of 'C' as 'G' and the same number of occurrences of 'A' as 'U', then the

bonding graphofcannot possibly possess aperfect matchingamong itsbasepair edges. For example, seeFigure 1; in fact, most bonding graphs will not contain a perfect matching.

In light of this fact, we define amaximum matchingin a graph as amatchingcontaining as manyedgesas possible. SeeFigure 2for three maximum matchings in graphs.

A maximum matching of basepair edges will correspond to a way of forming as many base pairs as possible in an RNA string, as shown inFigure 3.

Given:An RNA stringof length at most 100.

Return:The total possible number of maximum matchings of basepair edges in the bonding graph of.

在上面的引言中表示的圖的理論圖類似物是,如果我們的RNA字串的'C'的出現次數與'G'的發生次數不同,而'A'的出現數與'U'的發生次數相同”,則粘結圖形的不可能擁有完美匹配其之間鹼基對的邊緣。例如,參見圖1。實際上,大多數繫結圖不會包含完美匹配。

鑑於這一事實,我們將圖形中的最大匹配定義為包含儘可能多的匹配。有關圖形中的三個最大匹配,請參見圖2

鹼基對邊緣的最大匹配將對應於在RNA串中形成儘可能多的鹼基對的方式,如圖3所示。

給定:長度不超過100的RNA字串。

返回值:的鍵合圖中鹼基對邊的最大匹配總數。

Sample Dataset

>Rosalind_92
AUGCUUC

Sample Output

6