Rosalind第33题:Catalan Numbers and RNA Secondary Structures

Problem

Figure 3. The only two noncrossing perfect matchings of basepair edges (shown in red) for the RNA string UAGCGUGAUCAC.

Figure 4. All possible noncrossing perfect matchings in complete graphs on 2, 4, 6, and 8 nodes; the total number of such matchings are 1, 2, 5, and 14, respectively.

matching in a graph is noncrossing if none of its edges cross each other. If we assume that the  nodes of this graph are arranged around a circle, and if we label these nodes with positive integers between 1 and , then a matching is noncrossing as long as there are not edges  and  such that .

A noncrossing matching of basepair edges in the bonding graph corresponding to an RNA string will correspond to a possible secondary structure of the underlying RNA strand that lacks pseudoknots, as shown in Figure 3.

In this problem, we will consider counting noncrossing perfect matchings of basepair edges. As a motivating example of how to count noncrossing perfect matchings, let  denote the number of noncrossing perfect matchings in the complete graph . After setting , we can see that  should equal 1 as well. As for the case of a general , say that the nodes of  are labeled with the positive integers from 1 to . We can join node 1 to any of the remaining  nodes; yet once we have chosen this node (say ), we cannot add another edge to the matching that crosses the edge . As a result, we must match all the edges on one side of  to each other. This requirement forces  to be even, so that we can write  for some positive integer .

There are  nodes on one side of  and  nodes on the other side of , so that in turn there will be  different ways of forming a perfect matching on the remaining nodes of . If we let  vary over all possible  choices of even numbers between 1 and , then we obtain the recurrence relation . The resulting numbers  counting noncrossing perfect matchings in  are called the Catalan numbers, and they appear in a huge number of other settings. See Figure 4 for an illustration counting the first four Catalan numbers.

Given: An RNA string  having the same number of occurrences of 'A' as 'U' and the same number of occurrences of 'C' as 'G'. The length of the string is at most 300 bp.

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

匹配在一个曲线图noncrossing 如果没有其的边缘彼此交叉。如果我们假设 此图的节点围绕一个圆排列,并且用1到之间的正整数标记这些节点,则只要不存在边和,匹配就不会交叉。 

的noncrossing匹配碱基对的边缘接合图表对应于RNA串将对应于底层RNA的可能的二级结构链缺乏假结,如图 图3

在这个问题中,我们将考虑计算碱基对边的非交叉完美匹配。作为如何计算非交叉完美匹配的激励示例,让我们在完整图中表示非交叉完美匹配的数量。设置之后,我们可以看到它也应该等于1。对于一般情况,假设的节点标有从1到的正整数。我们可以将节点1连接到任何其他节点;然而,一旦我们选择了该节点(例如),就无法将另一个边添加到与该边相交的匹配中。结果,我们必须使一侧的所有边彼此匹配。这一要求迫使 成为偶数,以便我们可以写一些正整数。

有对的一面节点和节点上的另一边,所以这反过来将有形成的剩余节点上完美匹配不同的方式。如果我们让偶数的所有可能选择在1和之间变化,那么我们将获得递归关系。算出非交叉完美匹配的结果数字称为加泰罗尼亚语数字,它们出现在大量其他设​​置中。有关 对前四个加泰罗尼亚语数字进行计数的图示,请参见图4。 

给定:具有“ A”和“ U”相同出现次数以及“ C”和“ G”相同出现次数的RNA字符串。字符串的长度最多为300 bp。

返回:键对图中基对边的非交叉完全匹配的总数,模为1,000,000。

 

Sample Dataset

>Rosalind_57
AUAU

Sample Output

2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值