Rosalind第49题:Motzkin Numbers and RNA Secondary Structures

Problem

Figure 1. The 21 distinct ways to form a noncrossing matching on 5 labeled nodes. (Courtesy: Robertd, Wikimedia Commons User)

Figure 2. Two possible noncrossing matchings of basepair edges in the bonding graph corresponding to RNA string UAGCGUGAUCAC.

Similarly to our definition of the Catalan numbers, the -th Motzkin number  counts the number of ways to form a (not necessarily perfectnoncrossing matching in the complete graph  containing  nodes. For example, Figure 1 demonstrates that . Note in this figure that technically, the "trivial" matching that contains no edges at all is considered to be a matching, because it satisfies the defining condition that no two edges are incident to the same node.

How should we compute the Motzkin numbers? As with Catalan numbers, we will take . To calculate  in general, assume that the nodes of  are labeled around the outside of a circle with the integers between 1 and , and consider node 1, which may or may not be involved in a matching. If node 1 is not involved in a matching, then there are  ways of matching the remaining  nodes. If node 1 is involved in a matching, then say it is matched to node : this leaves  nodes on one side of edge  and  nodes on the other side; as with the Catalan numbers, no edge can connect the two sides, which gives us  ways of matching the remaining edges. Allowing  to vary between  and  yields the following recurrence relation for the Motzkin numbers: .

To count all possible secondary structures of a given RNA string that do not contain pseudoknots, we need to modify the Motzkin recurrence so that it counts only matchings of basepair edges in the bonding graph corresponding to the RNA string; see Figure 2.

Given: An RNA string  of length at most 300 bp.

Return: The total number of noncrossing matchings of basepair edges in the bonding graph of , modulo 1,000,000.

与我们对加泰罗尼亚语数字的定义类似,个Motzkin的数 计算在完整图中形成非交叉匹配(不一定完美) 的方式的数量  包含  节点。例如, 图1 演示了。注意,在该图中,从技术上讲,根本不包含边缘的“平凡”匹配被视为匹配,因为它满足了没有两个边缘入射到同一节点的定义条件。

我们应该如何计算莫兹金数?与加泰罗尼亚语数字一样,我们将采用。计算 通常,假设  在圆的外部用1到1之间的整数标记 ,并考虑可能不包含在匹配中的节点1。如果节点1参与匹配,则存在 匹配其余方式 节点。如果节点1参与匹配,然后说,这是相匹配的节点:这离开  边缘一侧的节点  和 另一侧的节点;与加泰罗尼亚数字一样,没有边可以连接两侧,这给了我们其余边缘的匹配方式。允许 在...之间变化  和 对于Motzkin数产生以下递归关系:。

要计算给定RNA字符串中不包含假结的所有可能的二级结构,我们需要修改Motzkin递归,以便仅计算与该RNA字符串相对应的键合图碱基对边缘的匹配。参见 图2

Sample Dataset

>Rosalind_57
AUAU

Sample Output

7
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值