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 perfect) noncrossing 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