# Luo gu 1140 similar gene

Source: Internet
Author: User

Luo gu 1140 similar gene

Topic background

As we all know, genes can be thought of as a base pair sequence. It contains 4 kinds of nucleotides, précis-writers as a,c,g,t. Biologists are working to find the function of human genes for the diagnosis of diseases and the invention of drugs. In the task of a human genome working group, biologists studied the similarity of two genes. Because this research has an unusual effect on the treatment of diseases.

Title Description

The similarity of two genes is calculated as follows:
For two known genes, such as AGTGATG and Gttag, their bases correspond to each other. Of course, some empty bases can be added to the middle--for example:

Thus, the similarity between the two genes can be described by the sum of the similarity between the bases, and the similarity between the bases is shown in the following table:

So the similarity is: (-3) +5+5+ (-2) + (-3) +5+ (-3) +5=9. Because the corresponding methods of the two genes are not unique, for example:

The similarity is: (-3) +5+5+ (-2) +5+ (-1) +5=14. The similarity of two genes is defined as the one with the greatest similarity among all correspondence methods.

Input/output format

Input format:

A total of two lines. Each line is first an integer representing the length of the gene, followed by a sequence of genes, with only a,c,g,t four letters in the sequence. The length of the 1<= sequence is <=100.

Output format:

Only one row, that is, the similarity of the input genes.

Input/Output sample

Input Sample # #:

7 AGTGATG

5 Gttag

Sample # # of output:

14

Ideas

linear DP.

Can be likened to the maximum common subsequence. Set D[I][J] to the maximum similarity to the J of the I and B strings of a string. Then there is the transfer equation:

D[i][j]=max{d[i-1][j-1]+cost (A[i],b[j]), D[i][j-1]+cost ('-', b[j]), D[i-1][j]+cost (A[i], '-')}

Note that initialize D[J] and d[i], the other string to the right one read into the convenience of processing.

Code

`1#include <cstdio>2#include <iostream>3 using namespacestd;4 5 Const intMAXN = -+Ten;6 Const intw={ 7{5,-1,-2,-1,-3},8{-1,5,-3,-2,-4},9{-2,-3,5,-2,-2},Ten{-1,-2,-2,5,-1}, One{-3,-4,-2,-1,-1<< -} A                 }; - inth,D[MAXN][MAXN]; - intn,m; the CharA[MAXN],B[MAXN]; -  -InlineintCostCharXChary) { -     returnW[h[x]][h[y]]; + } -  + intMain () { Ah['A']=0; h['C']=1; h['G']=2; h['T']=3; h['-']=4; at      -scanf"%d%s%d%s", &n,a+1, &m,b+1); -      for(intI=1; i<=n;i++) {d[i]=d[i-1]+cost (A[i],'-'); } -      for(intj=1; j<=m;j++) {d[j]=d[j-1]+cost ('-', B[j]); } -      -      for(intI=1; i<=n;i++) in         for(intj=1; j<=m;j++){ -d[i][j]=d[i-1][j-1]+Cost (A[i],b[j]); toD[i][j]=max (d[i][j],d[i-1][j]+cost (A[i],'-')); +D[i][j]=max (d[i][j],d[i][j-1]+cost (B[j],'-')); -        } theprintf"%d", D[n][m]); *     return 0; \$}`

Luo gu 1140 similar gene

Related Keywords:

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.