LA 3602 DNA Consensus String (brute Force enumeration)

Source: Internet
Author: User

Test instructions: Given a sequence of DNA of length n of M, a shortest sequence of DNA is obtained, which minimizes the total hamming distance.

Hamming the distance is equal to the number of different positions of characters.

Analysis: See this problem, my first feeling is to calculate the time complexity, good small, nothing, completely can violence, as long as the same position on each string,

The choice appears most, if has the same choice ASIIC code small (because requires the dictionary order small). Then record the maximum character and Hamming distance.

The code is as follows:

#include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector  >using namespace Std;const int maxn = n + 10;char S[55][maxn];char ans[maxn];int main () {int n, T, M, d, MM;    Cin >> T;        while (t--) {scanf ("%d%d", &m, &n);        for (int i = 0; i < m; ++i) scanf ("%s", S[i]);        d = 0;            for (int i = 0; i < n; ++i) {int cnta = 0, Cntc = 0, Cntg = 0, Cntt = 0;            MM = 0;                for (int j = 0; j < m; ++j) {if (' A ' = = S[j][i]) ++cnta;                else if (' C ' = = S[j][i]) ++cntc;                else if (' G ' = = S[j][i]) ++cntg;            else if (' T ' = = S[j][i]) ++cntt;  } mm = max (mm, cnta);  MM = max (mm, CNTC);//Find the maximum number of MM = max (mm, CNTG);            MM = max (mm, Cntt);  if (mm = = Cnta) {Ans[i] = ' A '; D + = CNTC;  D + = CNTG; D + = Cntt;  }//different positions Plus and else if (mm = = CNTC) {Ans[i] = ' C '; D + = Cnta; D + = CNTG; D + = Cntt;  } else if (mm = = CNTG) {Ans[i] = ' G '; D + = CNTC;  D + = Cnta; D + = Cntt;  } else if (mm = = Cntt) {Ans[i] = ' T '; D + = CNTC;  D + = CNTG; D + = Cnta;    }} Ans[n] = ' + ';//plus Terminator printf ("%s\n%d\n", ans, D); } return 0;}

LA 3602 DNA Consensus String (brute Force enumeration)

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.