UVa 1368-dna Consensus String

Source: Internet
Author: User

Find a sequence with the smallest total Hamming distance from the given sequence, and the smallest solution of the output dictionary order

Hamming distance is two different characters with several positions in a sequence

1#include <iostream>2 using namespacestd;3 intT,n,m,ans1,cnt,tmp1,tmp2,tmp3,tmp4;4 Chars[ -][1005],ans2[1005];5 voidjudge ()6 {7     if(tmp1>=tmp2&&tmp1>=tmp3&&tmp1>=tmp4)8     {9ans2[cnt++]='A';Tenans1+=tmp2+tmp3+Tmp4; One     }  A     Else if(tmp2>=tmp1&&tmp2>=tmp3&&tmp2>=tmp4) -     { -ans2[cnt++]='C'; theans1+=tmp1+tmp3+Tmp4; -     } -     Else if(tmp3>=tmp2&&tmp3>=tmp1&&tmp3>=tmp4) -     { +ans2[cnt++]='G'; -ans1+=tmp1+tmp2+Tmp4; +     } A     Else at     { -ans2[cnt++]='T'; -ans1+=tmp1+tmp2+Tmp3; -     } - } - voidfuc () in { -Ans1=cnt=0; to      for(intj=0; j<m;j++) +     { -tmp1=tmp2=tmp3=tmp4=0; the          for(intI=0; i<n;i++) *         { $             Switch(S[i][j])Panax Notoginseng             { -                  Case 'A': tmp1++; Break; the                  Case 'C': tmp2++; Break; +                  Case 'G': tmp3++; Break; A                  Case 'T': tmp4++; Break; the             } +         }     - judge (); $     } $ans2[cnt]=' /'; - } - intMain () the { -Cin>>T;Wuyi      while(t--) the     { -Cin>>n>>m; Wu          for(intI=0; i<n;i++) cin>>S[i]; - fuc (); Aboutcout<<ans2<<Endl; $cout<<ans1<<Endl; -     } -}

UVa 1368-dna Consensus String

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.