最大匹配和 RNA 二级结构
作者:L. Grondin
http://rosalind.info/problems/mmch/
示例输入
>Rosalind_92 AUGCUUC
示例输出
6
源代码:mmch-grondilu.pl
use v6; sub C($k, $n) { if $k < 0 or $k > $n { return 0 } elsif $k < 2 { return $n } elsif $k == $n { return 1 } else { return (state @)[$n][$k] //= C($k-1, $n-1) + C($k, $n-1) } } sub postfix:<!>(Int $n) { [*] 1 .. $n } my $default-input = q:to/END/; >Rosalind_92 AUGCUUC END sub MAIN($input-file = Nil) { my $input = $input-file ?? $input-file.IO.slurp !! $default-input; my $rna = $default-input.lines[1..*-1].join; given bag($rna.comb) { say C(.<A U>.min, .<A U>.max) * .<A U>.min! * C(.<C G>.min, .<C G>.max) * .<C G>.min!; } }