{"id":569,"date":"2012-11-16T13:34:51","date_gmt":"2012-11-16T05:34:51","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=569"},"modified":"2012-11-17T17:30:10","modified_gmt":"2012-11-17T09:30:10","slug":"rosalind-1","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/rosalind-1\/","title":{"rendered":"Rosalind 1"},"content":{"rendered":"<p><a href=\"http:\/\/rosalind.info\/problems\/as-graph\/\">http:\/\/rosalind.info\/problems\/as-graph\/<\/a><br \/>\n<a href=\"http:\/\/en.wikipedia.org\/wiki\/Bioinformatics\">http:\/\/en.wikipedia.org\/wiki\/Bioinformatics<\/a><\/p>\n<p><!--more--><\/p>\n<h3>\u5b57\u7b26\u4e32\u5904\u7406\u3001\u6b63\u5219\u8868\u8fbe\u5f0f<\/h3>\n<pre class=\"brush: ruby; collapse: true; light: false; title: DNA \u2014\u2014 Counting Nucleotides ; toolbar: true; notranslate\" title=\"DNA \u2014\u2014 Counting Nucleotides \">\r\ns = gets\r\nprint &#x5B;s.count('A'), s.count('C'), s.count('G'), s.count('T')] * ' '\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: RNA \u2014\u2014 RNA Transcription ; toolbar: true; notranslate\" title=\"RNA \u2014\u2014 RNA Transcription \">\r\nprint gets.gsub('T','U')\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: REVC \u2014\u2014 Reverse Complement ; toolbar: true; notranslate\" title=\"REVC \u2014\u2014 Reverse Complement \">\r\ns = gets\r\ns.gsub!('A','a'); s.gsub!('T','A'); s.gsub!('a','T')\r\ns.gsub!('C','c'); s.gsub!('G','C'); s.gsub!('c','G')\r\nprint s.reverse\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: GC \u2014\u2014 GC Content; toolbar: true; notranslate\" title=\"GC \u2014\u2014 GC Content\">\r\n$buf = gets()\r\n\r\ndef gc(s)\r\n\tgcc = 0.0\r\n\ts.each_char{|si|\t\t\r\n\t\tgcc += 1 if (si == 'G' || si == 'C') \r\n\t}\r\n\treturn gcc \/ s.size\r\nend\r\n\r\ndef getdna()\r\n\tdna = gets().chomp\r\n\tdna += $buf.chomp while ($buf = gets()) &amp;&amp; ($buf&#x5B;0] != '&gt;')\t\r\n\treturn dna\r\nend\r\n\r\ndna = &quot;$&quot;\r\n\r\nwhile $buf do\r\n\t_id, _dna = $buf&#x5B;1..-1], getdna()\t\t\r\n\tid, dna = _id, _dna if gc(_dna) &gt; gc(dna)\r\nend\r\n\r\nputs id\r\nprint gc(dna) * 100, '%'\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: HAMM \u2014\u2014 Counting Point Mutations; toolbar: true; notranslate\" title=\"HAMM \u2014\u2014 Counting Point Mutations\">\r\ns = gets.chomp; t = gets.chomp; dist = 0\r\n0.upto(s.size-1){|i|\r\n\tdist += 1 if s&#x5B;i] != t&#x5B;i]\t\t\r\n}\r\np dist\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: CONS \u2014\u2014 Consensus and Profile; toolbar: true; notranslate\" title=\"CONS \u2014\u2014 Consensus and Profile\">\r\ns = gets.chomp; n = s.length; a = Array.new(n){Hash.new(0)}\r\n\r\nbegin\t\r\n\t0.upto(n-1){|i|\r\n\t\ta&#x5B;i]&#x5B;s&#x5B;i]] += 1\r\n\t}\r\nend while s = gets\r\n\r\n\r\ndef scan(a, n, ch)\r\n\tprint ch,':'\r\n\t0.upto(n-1){|i|\r\n\t\tprint ' ', a&#x5B;i]&#x5B;ch]\r\n\t}\r\n\tputs\r\nend\r\n\r\n\r\ndef common(ai)\r\n\treturn 'A' if (ai&#x5B;'A'] &gt;= ai&#x5B;'C'] &amp;&amp; ai&#x5B;'A'] &gt;= ai&#x5B;'G'] &amp;&amp; ai&#x5B;'A'] &gt;= ai&#x5B;'T']) \t\r\n\treturn 'C' if (ai&#x5B;'C'] &gt;= ai&#x5B;'A'] &amp;&amp; ai&#x5B;'C'] &gt;= ai&#x5B;'G'] &amp;&amp; ai&#x5B;'C'] &gt;= ai&#x5B;'T']) \r\n\treturn 'G' if (ai&#x5B;'G'] &gt;= ai&#x5B;'A'] &amp;&amp; ai&#x5B;'G'] &gt;= ai&#x5B;'C'] &amp;&amp; ai&#x5B;'G'] &gt;= ai&#x5B;'T']) \r\n\treturn 'T'\r\nend\r\n\r\na.each{|ai|\r\n\t#ai.sort_by{|key, value| value}\r\n\t#print ai.begin().value\r\n\tprint common(ai)\r\n}\t\r\nputs\r\n\r\n\t\t\r\nscan(a, n, 'A'); scan(a, n, 'C'); scan(a, n, 'G'); scan(a, n, 'T')\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; light: false; title: GRPH \u2014\u2014 Overlap Graphs; toolbar: true; notranslate\" title=\"GRPH \u2014\u2014 Overlap Graphs\">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 1009;\r\n\r\npair&lt;string, string&gt; A&#x5B;N];\r\nint n;\r\n\r\nbool adj(string a, string b, int k){\r\n    if (a == b) return false;\r\n    REP(i, k) if (a&#x5B;SZ(a)-k+i] != b&#x5B;i]) return false;\r\n    return true;\r\n}\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    string id, dna; cin &gt;&gt; id; while (id&#x5B;0] == '&gt;'){\r\n        ERS(id, 0), A&#x5B;n].fi = id, CLR(dna);\r\n        while (cin &gt;&gt; id &amp;&amp; id&#x5B;0] != '&gt;') dna += id;\r\n        A&#x5B;n++].se = dna;\r\n    }\r\n\r\n    REP_2(i, j, n, n) if (adj(A&#x5B;i].se, A&#x5B;j].se, 3)){\r\n        cout &lt;&lt; A&#x5B;i].fi &lt;&lt; &quot; &quot; &lt;&lt; A&#x5B;j].fi &lt;&lt; endl;\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: PROT \u2014\u2014 Protein Translation; toolbar: true; notranslate\" title=\"PROT \u2014\u2014 Protein Translation\">\r\ndict = {\r\n    'UCA' =&gt; 'S',    # Serine\r\n    'UCC' =&gt; 'S',    # Serine\r\n    'UCG' =&gt; 'S',    # Serine\r\n    'UCU' =&gt; 'S',    # Serine\r\n    'UUC' =&gt; 'F',    # Phenylalanine\r\n    'UUU' =&gt; 'F',    # Phenylalanine\r\n    'UUA' =&gt; 'L',    # Leucine\r\n    'UUG' =&gt; 'L',    # Leucine\r\n    'UAC' =&gt; 'Y',    # Uyrosine\r\n    'UAU' =&gt; 'Y',    # Uyrosine\r\n    'UAA' =&gt; '_',    # Stop\r\n    'UAG' =&gt; '_',    # Stop\r\n    'UGC' =&gt; 'C',    # Cysteine\r\n    'UGU' =&gt; 'C',    # Cysteine\r\n    'UGA' =&gt; '_',    # Stop\r\n    'UGG' =&gt; 'W',    # Uryptophan\r\n    'CUA' =&gt; 'L',    # Leucine\r\n    'CUC' =&gt; 'L',    # Leucine\r\n    'CUG' =&gt; 'L',    # Leucine\r\n    'CUU' =&gt; 'L',    # Leucine\r\n    'CCA' =&gt; 'P',    # Proline\r\n    'CCC' =&gt; 'P',    # Proline\r\n    'CCG' =&gt; 'P',    # Proline\r\n    'CCU' =&gt; 'P',    # Proline\r\n    'CAC' =&gt; 'H',    # Histidine\r\n    'CAU' =&gt; 'H',    # Histidine\r\n    'CAA' =&gt; 'Q',    # Glutamine\r\n    'CAG' =&gt; 'Q',    # Glutamine\r\n    'CGA' =&gt; 'R',    # Arginine\r\n    'CGC' =&gt; 'R',    # Arginine\r\n    'CGG' =&gt; 'R',    # Arginine\r\n    'CGU' =&gt; 'R',    # Arginine\r\n    'AUA' =&gt; 'I',    # Isoleucine\r\n    'AUC' =&gt; 'I',    # Isoleucine\r\n    'AUU' =&gt; 'I',    # Isoleucine\r\n    'AUG' =&gt; 'M',    # Methionine\r\n    'ACA' =&gt; 'T',    # Uhreonine\r\n    'ACC' =&gt; 'T',    # Uhreonine\r\n    'ACG' =&gt; 'T',    # Uhreonine\r\n    'ACU' =&gt; 'T',    # Uhreonine\r\n    'AAC' =&gt; 'N',    # Asparagine\r\n    'AAU' =&gt; 'N',    # Asparagine\r\n    'AAA' =&gt; 'K',    # Lysine\r\n    'AAG' =&gt; 'K',    # Lysine\r\n    'AGC' =&gt; 'S',    # Serine\r\n    'AGU' =&gt; 'S',    # Serine\r\n    'AGA' =&gt; 'R',    # Arginine\r\n    'AGG' =&gt; 'R',    # Arginine\r\n    'GUA' =&gt; 'V',    # Valine\r\n    'GUC' =&gt; 'V',    # Valine\r\n    'GUG' =&gt; 'V',    # Valine\r\n    'GUU' =&gt; 'V',    # Valine\r\n    'GCA' =&gt; 'A',    # Alanine\r\n    'GCC' =&gt; 'A',    # Alanine\r\n    'GCG' =&gt; 'A',    # Alanine\r\n    'GCU' =&gt; 'A',    # Alanine\r\n    'GAC' =&gt; 'D',    # Aspartic Acid\r\n    'GAU' =&gt; 'D',    # Aspartic Acid\r\n    'GAA' =&gt; 'E',    # Glutamic Acid\r\n    'GAG' =&gt; 'E',    # Glutamic Acid\r\n    'GGA' =&gt; 'G',    # Glycine\r\n    'GGC' =&gt; 'G',    # Glycine\r\n    'GGG' =&gt; 'G',    # Glycine\r\n    'GGU' =&gt; 'G'    # Glycine    \r\n};\r\n\r\nmRNA = gets.chomp\r\nputs mRNA.gsub(\/\\w{3}\/).each(&amp;dict.method(:&#x5B;]))&#x5B;0..-1].gsub(\/_.*\/, '')\r\n<\/pre>\n<p>\u3002\u3002\u3002<a href=\"http:\/\/en.wikipedia.org\/wiki\/MRNA\">mRNA<\/a>\u3001<a href=\"http:\/\/en.wikipedia.org\/wiki\/Protein\">\u86cb\u767d\u8d28\uff08Protein\uff09<\/a>\u3001<a href=\"http:\/\/en.wikipedia.org\/wiki\/Amino_acid\">\u6c28\u57fa\u9178\uff08Amino Acid\uff09<\/a>\u3001<a href=\"http:\/\/en.wikipedia.org\/wiki\/Genetic_code#RNA_codon_table\">\u5bc6\u7801\u5b50\uff08Genetic Code\uff09<\/a>\u3002\u3002\u3002<\/p>\n<pre class=\"brush: ruby; collapse: true; light: false; title: SPLC \u2014\u2014 RNA Splicing ; toolbar: true; notranslate\" title=\"SPLC \u2014\u2014 RNA Splicing \">\r\ndict = {\r\n    'TCA' =&gt; 'S',    # Serine\r\n    'TCC' =&gt; 'S',    # Serine\r\n    'TCG' =&gt; 'S',    # Serine\r\n    'TCT' =&gt; 'S',    # Serine\r\n    'TTC' =&gt; 'F',    # Phenylalanine\r\n    'TTT' =&gt; 'F',    # Phenylalanine\r\n    'TTA' =&gt; 'L',    # Leucine\r\n    'TTG' =&gt; 'L',    # Leucine\r\n    'TAC' =&gt; 'Y',    # Tyrosine\r\n    'TAT' =&gt; 'Y',    # Tyrosine\r\n    'TAA' =&gt; '_',    # Stop\r\n    'TAG' =&gt; '_',    # Stop\r\n    'TGC' =&gt; 'C',    # Cysteine\r\n    'TGT' =&gt; 'C',    # Cysteine\r\n    'TGA' =&gt; '_',    # Stop\r\n    'TGG' =&gt; 'W',    # Tryptophan\r\n    'CTA' =&gt; 'L',    # Leucine\r\n    'CTC' =&gt; 'L',    # Leucine\r\n    'CTG' =&gt; 'L',    # Leucine\r\n    'CTT' =&gt; 'L',    # Leucine\r\n    'CCA' =&gt; 'P',    # Proline\r\n    'CCC' =&gt; 'P',    # Proline\r\n    'CCG' =&gt; 'P',    # Proline\r\n    'CCT' =&gt; 'P',    # Proline\r\n    'CAC' =&gt; 'H',    # Histidine\r\n    'CAT' =&gt; 'H',    # Histidine\r\n    'CAA' =&gt; 'Q',    # Glutamine\r\n    'CAG' =&gt; 'Q',    # Glutamine\r\n    'CGA' =&gt; 'R',    # Arginine\r\n    'CGC' =&gt; 'R',    # Arginine\r\n    'CGG' =&gt; 'R',    # Arginine\r\n    'CGT' =&gt; 'R',    # Arginine\r\n    'ATA' =&gt; 'I',    # Isoleucine\r\n    'ATC' =&gt; 'I',    # Isoleucine\r\n    'ATT' =&gt; 'I',    # Isoleucine\r\n    'ATG' =&gt; 'M',    # Methionine\r\n    'ACA' =&gt; 'T',    # Threonine\r\n    'ACC' =&gt; 'T',    # Threonine\r\n    'ACG' =&gt; 'T',    # Threonine\r\n    'ACT' =&gt; 'T',    # Threonine\r\n    'AAC' =&gt; 'N',    # Asparagine\r\n    'AAT' =&gt; 'N',    # Asparagine\r\n    'AAA' =&gt; 'K',    # Lysine\r\n    'AAG' =&gt; 'K',    # Lysine\r\n    'AGC' =&gt; 'S',    # Serine\r\n    'AGT' =&gt; 'S',    # Serine\r\n    'AGA' =&gt; 'R',    # Arginine\r\n    'AGG' =&gt; 'R',    # Arginine\r\n    'GTA' =&gt; 'V',    # Valine\r\n    'GTC' =&gt; 'V',    # Valine\r\n    'GTG' =&gt; 'V',    # Valine\r\n    'GTT' =&gt; 'V',    # Valine\r\n    'GCA' =&gt; 'A',    # Alanine\r\n    'GCC' =&gt; 'A',    # Alanine\r\n    'GCG' =&gt; 'A',    # Alanine\r\n    'GCT' =&gt; 'A',    # Alanine\r\n    'GAC' =&gt; 'D',    # Aspartic Acid\r\n    'GAT' =&gt; 'D',    # Aspartic Acid\r\n    'GAA' =&gt; 'E',    # Glutamic Acid\r\n    'GAG' =&gt; 'E',    # Glutamic Acid\r\n    'GGA' =&gt; 'G',    # Glycine\r\n    'GGC' =&gt; 'G',    # Glycine\r\n    'GGG' =&gt; 'G',    # Glycine\r\n    'GGT' =&gt; 'G'    # Glycine   \r\n};\r\n\r\ndna = gets.chomp\r\n\r\nwhile exon = gets do\r\n\tdna.gsub!(exon.chomp, '')\r\nend\r\n\r\nputs dna.gsub(\/\\w{3}\/).each(&amp;dict.method(:&#x5B;]))&#x5B;0..-1].gsub(\/_.*\/, '')\r\n<\/pre>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Exon\">\u5916\u663e\u5b50\uff08Exon\uff09<\/a>\u3001<a href=\"http:\/\/en.wikipedia.org\/wiki\/Intron\">\u5185\u542b\u5b50\uff08Intron\uff09<\/a><\/p>\n<pre class=\"brush: ruby; collapse: true; light: false; title: REVP \u2014\u2014 Locating Restriction Sites; toolbar: true; notranslate\" title=\"REVP \u2014\u2014 Locating Restriction Sites\">\r\ns = gets.chomp; n = s.length\r\n\r\ndef cp(a, b)\r\n\treturn a == 'G' &amp;&amp; b == 'C' || a == 'C' &amp;&amp; b == 'G' || a == 'A' &amp;&amp; b == 'T' || a == 'T' &amp;&amp; b == 'A'\r\nend\r\n\r\ndef test(s)\t\r\n\tn = s.length\r\n\t0.upto(n\/2){|i|\r\n\t\treturn false if !cp(s&#x5B;i], s&#x5B;n-1-i])\r\n\t}\r\n\treturn true\r\nend\r\n\r\n4.upto(8){|len|\t\r\n\tnext if len.odd?\t\r\n\t0.upto(n-len){|l|\r\n\t\tr = l + len - 1\r\n\t\tprint l+1, ' ', len, &quot;\\n&quot; if (test(s&#x5B;l..r]))\r\n\t}\r\n}\r\n<\/pre>\n<h3>\u6982\u7387<\/h3>\n<pre class=\"brush: ruby; collapse: true; light: false; title: PROB \u2014\u2014 Introduction to Probability; toolbar: true; notranslate\" title=\"PROB \u2014\u2014 Introduction to Probability\">\r\nI =-&gt;{gets.split.map &amp;:to_f}\r\nI&#x5B;].each{|ai|\t\r\n\tp (ai**2 + (1-ai)**2) \/ 2\r\n}\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: EVAL \u2014\u2014 Introduction to Expected Value; toolbar: true; notranslate\" title=\"EVAL \u2014\u2014 Introduction to Expected Value\">\r\nI =-&gt;{gets.split.map &amp;:to_f}\r\nm, n = I&#x5B;]\r\n\r\nI&#x5B;].each{|ai|  \t\r\n    p (n - m + 1) * ((ai**2 + (1-ai)**2) \/ 2) ** m\r\n}\r\n<\/pre>\n<h3>\u5b57\u7b26\u4e32\u5339\u914d<\/h3>\n<pre class=\"brush: ruby; collapse: true; light: false; title: SUBS \u2014\u2014 Finding a Motif in DNA ; toolbar: true; notranslate\" title=\"SUBS \u2014\u2014 Finding a Motif in DNA \">\r\nT = gets().chomp\r\nP = gets().chomp\r\n\r\nTn, Pn = T.length, P.length\r\n\r\nPi = &#x5B;]; Pi&#x5B;0] = j = -1\r\n\r\n0.upto(Pn-1){|i|\r\n\tj = Pi&#x5B;j] while (j &gt;= 0 &amp;&amp; P&#x5B;i] != P&#x5B;j])\r\n\ti += 1; j += 1; Pi&#x5B;i] = P&#x5B;i] == P&#x5B;j] ? Pi&#x5B;j] : j\t\r\n}\r\n\r\nj = 0\r\n\r\n0.upto(Tn-1){|i|\r\n\tj = Pi&#x5B;j] while (j &gt;= 0 &amp;&amp; T&#x5B;i] != P&#x5B;j])\r\n\ti += 1; j += 1; p i-Pn+1 if j == Pn\r\n}\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: KMP \u2014\u2014 Speeding Up Motif Finding ; toolbar: true; notranslate\" title=\"KMP \u2014\u2014 Speeding Up Motif Finding \">\r\nP = gets().chomp + '$'\r\nPn = P.length\r\n\r\n\r\nPi = &#x5B;]; Pi&#x5B;0], Pi&#x5B;1], i, j = -1, 0, 2, 0\r\n\r\nwhile (i &lt; Pn) do\r\n\tif (P&#x5B;i-1] == P&#x5B;j]) then\r\n\t\tj +=1; Pi&#x5B;i] = j; i += 1\r\n\telse\r\n\t\tif (j &gt; 0) then \r\n\t\t\tj = Pi&#x5B;j]\r\n\t\telse \r\n\t\t\tPi&#x5B;i] = 0; i += 1\r\n\t\tend\r\n\tend\r\nend\r\n\r\nputs Pi&#x5B;1..-1]*' '\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: SSEQ \u2014\u2014 Finding a Spliced Motif; toolbar: true; notranslate\" title=\"SSEQ \u2014\u2014 Finding a Spliced Motif\">\r\ns = gets.chomp\r\nt = gets.chomp\r\n\r\ni = 0; t.each_char{|ti|\r\n\ti += 1 while s&#x5B;i] != ti; i += 1;\r\n\tp i\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; light: false; title: LCS \u2014\u2014 Finding a Shared Motif; toolbar: true; notranslate\" title=\"LCS \u2014\u2014 Finding a Shared Motif\">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 1009;\r\n\r\nstring S&#x5B;N]; int dp&#x5B;N]&#x5B;N];\r\nint n;\r\n\r\nvoid check(string s){\r\n    FOR(i, 1, n) if (S&#x5B;i].find(s) == string::npos) return;\r\n    OT(s), exit(0);\r\n}\r\n\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    string s; while (cin &gt;&gt; s){\r\n        S&#x5B;n++] = s;\r\n    }\r\n\r\n    FOR(i, 1, n) if (SZ(S&#x5B;i]) &lt; SZ(S&#x5B;0])) swap(S&#x5B;0], S&#x5B;i]);\r\n\r\n    int n0 = SZ(S&#x5B;0]); DWN(len, n0-1, 0){\r\n        REP(i, n0-len){\r\n            s = S&#x5B;0].substr(i, len);\r\n            check(s);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<h3>\u751f\u6210\u6392\u5217\u3001\u7ec4\u5408<\/h3>\n<pre class=\"brush: cpp; collapse: true; light: false; title: PERM \u2014\u2014 Enumerating Gene Orders ; toolbar: true; notranslate\" title=\"PERM \u2014\u2014 Enumerating Gene Orders \">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 10;\r\nint A&#x5B;N];\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    int n, f = 1; REP_1_C(i, RD(n)) A&#x5B;i] = i, f *= i;\r\n\r\n    printf(&quot;%d\\n&quot;, f); DO(f){\r\n        REP_1(i, n) OT(A&#x5B;i]);\r\n        next_permutation(A + 1, A + n + 1);\r\n        puts(&quot;&quot;);\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; light: false; title: SIGN \u2014\u2014 Enumerating Oriented Gene Orderings; toolbar: true; notranslate\" title=\"SIGN \u2014\u2014 Enumerating Oriented Gene Orderings\">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 10;\r\nint A&#x5B;N];\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    int n, f = 1; REP_1_C(i, RD(n)) A&#x5B;i] = i, f *= i;\r\n    printf(&quot;%d\\n&quot;, f*_1(n)); DO(f){\r\n        REP(s, _1(n)){\r\n            REP_1(j, n){\r\n                if (!_1(s, (n-j))) putchar('-');\r\n                OT(A&#x5B;j]);\r\n            }\r\n            puts(&quot;&quot;);\r\n        }\r\n        next_permutation(A + 1, A + n + 1);\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; light: false; title: LEXF \u2014\u2014 Enumerating k-mers Lexicographically; toolbar: true; notranslate\" title=\"LEXF \u2014\u2014 Enumerating k-mers Lexicographically\">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 10;\r\nchar S&#x5B;N]; int A&#x5B;N];\r\nint n; LL k;\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    char str&#x5B;100]; gets(str);\r\n    REP_C(i, strlen(str)) if (str&#x5B;i] != ' ') S&#x5B;n++] = str&#x5B;i];\r\n    RD(k); DO(pow(n, k)){\r\n        DWN(i, k, 0) putchar(S&#x5B;A&#x5B;i]]); puts(&quot;&quot;);\r\n        A&#x5B;0]++; for (int i=0;A&#x5B;i]==n;A&#x5B;i]=0,++A&#x5B;++i]);\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; light: false; title: LEXV \u2014\u2014 Ordering Strings of Varying Length Lexicographically; toolbar: true; notranslate\" title=\"LEXV \u2014\u2014 Ordering Strings of Varying Length Lexicographically\">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 15;\r\n\r\nchar C&#x5B;N]; int A&#x5B;N];\r\nint n, k;\r\n\r\nvoid dfs(int dep = 0){\r\n    if (dep){\r\n        REP(i, dep) putchar(i&#x5B;A]&#x5B;C]);\r\n        puts(&quot;&quot;);\r\n    }\r\n\r\n    if (dep == k) return;\r\n    REP(i, n) A&#x5B;dep]=i, dfs(dep+1);\r\n}\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    char str&#x5B;109]; REP_C(i, strlen(gets(str))) if (str&#x5B;i] != ' ')\r\n        C&#x5B;n++] = str&#x5B;i];\r\n    RD(k);\r\n\r\n    dfs();\r\n}\r\n<\/pre>\n<h3>\u641c\u7d22<\/h3>\n<pre class=\"brush: cpp; collapse: true; light: false; title: REAR \u2014\u2014 Reversal Distance; toolbar: true; notranslate\" title=\"REAR \u2014\u2014 Reversal Distance\">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int F&#x5B;11] = {1,1,2,6,24,120,720,5040,40320,362880,3628800};\r\nconst int N = 10, L = 3628800;\r\nint n = 10;\r\n\r\nint D&#x5B;L]; int a&#x5B;N], st, ed; bool c&#x5B;N];\r\n\r\nint encode(){ \/\/ Cantor\r\n    int x = 0; REP(i, n){\r\n        int t = 0; FOR(j, i+1, n)\r\n            if (a&#x5B;i]&gt;a&#x5B;j]) ++t;\r\n        x = x * (n-i) + t;\r\n    }\r\n    return x;\r\n}\r\n\r\nvoid decode(int x){\r\n    RST(a, c); REP(i, n){\r\n        while (i&#x5B;a]&#x5B;c]) ++a&#x5B;i];\r\n        while (x &gt;= F&#x5B;n-i-1]){\r\n            x -= F&#x5B;n-i-1]; ++a&#x5B;i];\r\n            while (i&#x5B;a]&#x5B;c]) ++a&#x5B;i];\r\n        }\r\n        i&#x5B;a]&#x5B;c] = true;\r\n    }\r\n}\r\n\r\nvoid rev(int l, int r){\r\n    REP(i, (r - l + 1) \/ 2)\r\n        swap(a&#x5B;l+i], a&#x5B;r-i]);\r\n}\r\n\r\nint Q&#x5B;L], cz, op; int bfs(){\r\n    if (st == ed) return 0;\r\n    Q&#x5B;cz = 0] = st, op = 1;\r\n    RST(D); D&#x5B;st] = 1;\r\n    while (cz &lt; op){\r\n        int u = Q&#x5B;cz++]; decode(u);\r\n        FOR(len, 1, n){\r\n            REP(l, n - len){\r\n                int r = l + len; rev(l, r); int v = encode(); rev(l, r);\r\n                if (D&#x5B;v]) continue;\r\n                if (v == ed) return D&#x5B;u];\r\n                Q&#x5B;op++] = v;\r\n                D&#x5B;v] = D&#x5B;u] + 1;\r\n            }\r\n        }\r\n    }\r\n    return -1;\r\n}\r\n\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    while (~scanf(&quot;%d&quot;, &amp;a&#x5B;0])){\r\n        FOR(i, 1, n) --RD(a&#x5B;i]); st = encode();\r\n        REP(i, n) --RD(a&#x5B;i]); ed = encode();\r\n        OT(bfs());\r\n    }\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; light: false; title: SORT \u2014\u2014 Sorting by Reversals; toolbar: true; notranslate\" title=\"SORT \u2014\u2014 Sorting by Reversals\">\r\n\/* .................................................................................................................................. *\/\r\n\r\ntemplate&lt;class T1, class T2&gt; ostream&amp; operator &lt;&lt;(ostream&amp; cout, const pair&lt;T1, T2&gt; &amp;rhs){\r\n    cout &lt;&lt; rhs.fi+1 &lt;&lt; &quot; &quot; &lt;&lt; rhs.se+1;\r\n    return cout;\r\n}\r\n\r\nconst int F&#x5B;11] = {1,1,2,6,24,120,720,5040,40320,362880,3628800};\r\nconst int N = 10, L = 3628800;\r\nint n = 10;\r\n\r\nint D&#x5B;L], pre&#x5B;L]; PII opt&#x5B;L]; int a&#x5B;N], st, ed; bool c&#x5B;N];\r\n\r\nint encode(){ \/\/ Cantor\r\n    int x = 0; REP(i, n){\r\n        int t = 0; FOR(j, i+1, n)\r\n            if (a&#x5B;i]&gt;a&#x5B;j]) ++t;\r\n        x = x * (n-i) + t;\r\n    }\r\n    return x;\r\n}\r\n\r\nvoid decode(int x){\r\n    RST(a, c); REP(i, n){\r\n        while (i&#x5B;a]&#x5B;c]) ++a&#x5B;i];\r\n        while (x &gt;= F&#x5B;n-i-1]){\r\n            x -= F&#x5B;n-i-1]; ++a&#x5B;i];\r\n            while (i&#x5B;a]&#x5B;c]) ++a&#x5B;i];\r\n        }\r\n        i&#x5B;a]&#x5B;c] = true;\r\n    }\r\n}\r\n\r\nvoid rev(int l, int r){\r\n    REP(i, (r - l + 1) \/ 2)\r\n        swap(a&#x5B;l+i], a&#x5B;r-i]);\r\n}\r\n\r\nvoid print_path(int v){\r\n    if (v == st) return;\r\n    print_path(pre&#x5B;v]);\r\n    cout &lt;&lt; opt&#x5B;v] &lt;&lt; endl;\r\n}\r\n\r\nint Q&#x5B;L], cz, op; void bfs(){\r\n    if (st == ed) {puts(0); return;}\r\n    Q&#x5B;cz = 0] = st, op = 1;\r\n    RST(D); D&#x5B;st] = 1;\r\n    while (cz &lt; op){\r\n        int u = Q&#x5B;cz++]; decode(u);\r\n        FOR(len, 1, n){\r\n            REP(l, n - len){\r\n                int r = l + len; rev(l, r); int v = encode(); rev(l, r);\r\n                if (D&#x5B;v]) continue; opt&#x5B;v] = MP(l, r), pre&#x5B;v] = u;\r\n                if (v == ed){OT(D&#x5B;u]), print_path(v); return;}\r\n                Q&#x5B;op++] = v, D&#x5B;v] = D&#x5B;u] + 1;\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    while (~scanf(&quot;%d&quot;, &amp;a&#x5B;0])){\r\n        FOR(i, 1, n) --RD(a&#x5B;i]); st = encode();\r\n        REP(i, n) --RD(a&#x5B;i]); ed = encode();\r\n        bfs();\r\n    }\r\n}\r\n<\/pre>\n<h3>\u52a8\u6001\u89c4\u5212<\/h3>\n<pre class=\"brush: cpp; collapse: true; light: false; title: LCSQ \u2014\u2014 Finding a Shared Spliced Motif; toolbar: true; notranslate\" title=\"LCSQ \u2014\u2014 Finding a Shared Spliced Motif\">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 1009;\r\n\r\nchar A&#x5B;N], B&#x5B;N];\r\nint dp&#x5B;N]&#x5B;N], n, m;\r\n\r\nvoid print_path(int i, int j){\r\n    if (!i || !j) return;\r\n    if (A&#x5B;i] == B&#x5B;j] &amp;&amp; dp&#x5B;i]&#x5B;j] == dp&#x5B;i-1]&#x5B;j-1] + 1){\r\n        print_path(i-1, j-1), putchar(A&#x5B;i]);\r\n    }\r\n    else if (dp&#x5B;i-1]&#x5B;j] &gt; dp&#x5B;i]&#x5B;j-1]){\r\n        print_path(i-1, j);\r\n    }\r\n    else{\r\n        print_path(i, j-1);\r\n    }\r\n}\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    RS(A+1), RS(B+1), n = strlen(A+1), m = strlen(B+1);\r\n\r\n    REP_2_1(i, j, n, m){\r\n        dp&#x5B;i]&#x5B;j] = max(dp&#x5B;i-1]&#x5B;j], dp&#x5B;i]&#x5B;j-1]);\r\n        if (A&#x5B;i] == B&#x5B;j]) checkMax(dp&#x5B;i]&#x5B;j], dp&#x5B;i-1]&#x5B;j-1] + 1);\r\n    }\r\n\r\n    print_path(n, m);\r\n}\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: EDIT \u2014\u2014 Edit Distance; toolbar: true; notranslate\" title=\"EDIT \u2014\u2014 Edit Distance\">\r\ns = gets.chomp; n = s.length; s = '$' + s\r\nt = gets.chomp; m = t.length; t = '$' + t\r\n\r\ndp = Array.new(n+1){Array.new(m+1){0}}\r\n\r\ndef min(a, b)\r\n\treturn a &lt; b ? a : b\r\nend\r\n\r\n1.upto(n){|i|\r\n\tdp&#x5B;0]&#x5B;i] = dp&#x5B;i]&#x5B;0] = i\r\n}\r\n\r\n1.upto(n){|i|\r\n\t1.upto(m){|j|\t\t\r\n\t\tdp&#x5B;i]&#x5B;j] = min(min(dp&#x5B;i-1]&#x5B;j], dp&#x5B;i]&#x5B;j-1]) + 1, dp&#x5B;i-1]&#x5B;j-1] + (s&#x5B;i] != t&#x5B;j] ? 1 : 0))\r\n\t}\r\n}\r\n\r\np dp&#x5B;n]&#x5B;m]\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title: EDTA \u2014\u2014 Edit Distance Alignment; toolbar: true; notranslate\" title=\"EDTA \u2014\u2014 Edit Distance Alignment\">\r\ns = gets.chomp; n = s.length; s = '$' + s\r\nt = gets.chomp; m = t.length; t = '$' + t\r\n\r\ndp = Array.new(n+1){Array.new(m+1){0}}\r\n\r\ndef min(a, b)\r\n\treturn a &lt; b ? a : b\r\nend\r\n\r\n1.upto(n){|i|\r\n\tdp&#x5B;0]&#x5B;i] = dp&#x5B;i]&#x5B;0] = i\r\n}\r\n\r\n1.upto(n){|i|\r\n\t1.upto(m){|j|\t\t\r\n\t\tdp&#x5B;i]&#x5B;j] = min(min(dp&#x5B;i-1]&#x5B;j], dp&#x5B;i]&#x5B;j-1]) + 1, dp&#x5B;i-1]&#x5B;j-1] + (s&#x5B;i] != t&#x5B;j] ? 1 : 0))\r\n\t}\r\n}\r\n\r\n# build alignment .. .\r\ns_ = t_ = ''; i, j = n, m\r\nwhile !i.zero? || !j.zero? do\t\r\n\tif (j.zero? || dp&#x5B;i]&#x5B;j] == dp&#x5B;i-1]&#x5B;j] + 1) then\r\n\t\ts_ += s&#x5B;i]; t_ += '-'\r\n\t\ti -= 1\r\n\telsif (i.zero? || dp&#x5B;i]&#x5B;j] == dp&#x5B;i]&#x5B;j-1] + 1) then\r\n\t\ts_ += '-'; t_ += t&#x5B;j]\r\n\t\tj -= 1\r\n\telse\t\t\r\n\t\ts_ += s&#x5B;i]; t_ += t&#x5B;j]\t\t\r\n\t\ti -= 1; j -= 1\r\n\tend\r\nend\r\n\r\ns_.reverse!; t_.reverse!\r\nputs dp&#x5B;n]&#x5B;m], s_, t_\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; light: false; title:  \u2014\u2014 ; toolbar: true; notranslate\" title=\" \u2014\u2014 \">\r\n<\/pre>\n<pre class=\"brush: ruby; collapse: true; light: false; title:  \u2014\u2014 ; toolbar: true; notranslate\" title=\" \u2014\u2014 \">\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/rosalind.info\/problems\/as-graph\/ http:\/\/en.wikipedia.org\/wiki\/Bioinformatics<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-569","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-9b","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/569","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=569"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/569\/revisions"}],"predecessor-version":[{"id":570,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/569\/revisions\/570"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}