Huaman Gene Functions

Source: Internet
Author: User

Huaman Gene Functions

Algorithm analysis:

/*

From this analysis, we can see that it is the deformation of the oldest generation sequence (LCS.
Assume that the two subsequences are X and Y respectively;
Xi = (x1, x2. .. xi), Yj = (y1, y2.. yj) are the first I and j subsequences of the two subsequences respectively.
Returns the largest gender sequence;
1. When xi = yj, dp [I] [j] = dp [I-1] [J-1] + 1
2. When xi! When the value is yj, dp [I] [j] = max (dp [I-1] [j], dp [I] [J-1]).


This is a variant of LCS.
Set dp [I] [j] to take the maximum score of the s1 I character and s2 j character
There are three conditions for determining the optimal dp (the score of matrix [] [] is s1 [I] and s2 [j ):
1. s1 takes the I letter, s2 takes the "-": dp [I-1] [j] + matrix [s1 [I] ['-'];
2. s1 takes "-", s2 takes the j-letter: dp [I] [J-1] + matrix ['-'] [s2 [j];
3. s1 takes the I letter, s2 takes the j letter: dp [I-1] [J-1] + matrix [s1 [I] [s2 [j];
That is, dp [I] [j] = max (dp [I-1] [j] + matrix [s1 [I] ['-'],
Dp [I] [J-1] + matrix ['-'] [s2 [j],
Dp [I-1] [J-1] + matrix [s1 [I] [s2 [j]);

Initialization:

1. dp [0] [0] = 0;

2. dp [I] [0] (I belongs to (1, s1.length ))
Dp [I] [0] = matrix [s1 [I] ['-'];
Dp [0] [j] (j belongs to (1, s2.length ))
Dp [0] [j] = matrix ['-'] [s2 [j]
Note: matrix [] [] can be defined as an array of the int type. Here, we use characters to replace the array dimension values for ease of description.

*/

# Include
 
  
# Include
  
   
# Include
   
    
# Define MAXVALUE 101 using namespace std; int switchint (char t) {if (t = 'A') return 0; if (t = 'C') return 1; if (t = 'G') return 2; if (t = 'T') return 3; if (T = '-') return 4 ;} int getmaxs (int x, int y, int z) {int temp; if (x> y) temp = x; else temp = y; return temp> z? Temp: z;} int main () {int length1, leng22. // record the s1 and s2 sequence lengths int times, respectively. // number of cycles char s1 [MAXVALUE]; char s2 [MAXVALUE]; int dp [MAXVALUE] [MAXVALUE]; // used to record the length of the sub-column. // first, we create a matrix two-dimensional integer array to record the length of the score int matrix [5] [5] = {5,-1,-2, -1,-3,-,-3,-2,-4,-2,-,-2,-2,-1,-2, -1,-3,-4,-2,-}; // * we use 0 to represent // This function is used to convert characters into integer values, the objective is to build a matrix integer array cin> times; while (times --) {cin> length1; for (int I = 1; I <= length1; I ++) cin> s1 [I]; cin> leng22. for (int I = 1; I <= leng2; I ++) cin> s2 [I]; // # region initialize memset (dp, 0, sizeof (dp); for (int I = 1; I <= length1; I ++) {int temp = switchint (s1 [I]); dp [I] [0] = dp [I-1] [0] + matrix [temp] [4];} for (int j = 1; j <= leng2; j ++) {int temp = switchint (s2 [j]); dp [0] [j] = dp [0] [J-1] + matrix [4] [temp];} // # endregion for (int I = 1; I <= length1; I ++) {for (int j = 1; j <= leng2; j ++) {// dp [I] [j] = max (dp [I-1] [J-1] + matrix [switchint (s1 [I])] [switchint (s2 [j])], dp [I-1] [j] + matrix [switchint (s1 [I])] [4], dp [I] [J-1] + matrix [4] [switchint (s2 [j]); int t1 = dp [I-1] [J-1] + matrix [switchint (s1 [I])] [switchint (s2 [j])]; int t2 = dp [I-1] [j] + matrix [switchint (s1 [I])] [4]; int t3 = dp [I] [J-1] + matrix [4] [switchint (s2 [j])]; dp [I] [j] = getmaxs (t1, t2, t3) ;}} cout <
    
     




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.