Poj1080 Human Gene Functions lcs Deformation

Source: Internet
Author: User

Human Gene Functions
Time Limit: 1000 MS Memory Limit: 10000 K
Total Submissions: 14197 Accepted: 7864
Description
It is well known that a human gene can be considered as a sequence, consisting of four nucleus otides, which are simply denoted by four letters, A, C, G, and T. biologists have been interested in identifying human genes and determining their functions, because these can be used to diagnose human diseases and to design new drugs for them.

A human gene can be identified through a series of time-consuming biological experiments, often with the help of computer programs. once a sequence of a gene is obtained, the next job is to determine its function.
One of the methods for biologists to use in determining the function of a new gene sequence that they have just identified is to search a database with the new gene as a query. the database to be searched stores into gene sequences and their functions � many researchers have been submitting their genes and functions to the database and the database is freely accessible through the Internet.

A database search will return a list of gene sequences from the database that are similar to the query gene.
Biologists assume that sequence similarity often implies functional similarity. so, the function of the new gene might be one of the functions that the genes from the list have. to exactly determine which one is the right one another series of biological experiments will be needed.

Your job is to make a program that compares two genes and determines their similarity as explained below. Your program may be used as a part of the database search if you can provide an efficient one.
Given two genes AGTGATG and GTTAG, how similar are they? One of the methods to measure the similarity
Of two genes is called alignment. In an alignment, spaces are inserted, if necessary, in appropriate positions
The genes to make them equally long and score the resulting genes according to a scoring matrix.

For example, one space is inserted into AGTGATG to result in AGTGAT-G, and three spaces are inserted into GTTAG to result in too many T--TAG. A space is denoted by a minus sign (-). the two genes are now of equal
Length. These two strings are aligned:

AGTGAT-G
GT--TAG

In this alignment, there are four matches, namely, G in the second position, T in the third, T in the sixth, and G in the eighth. each pair of aligned characters is assigned a score according to the following scoring matrix.


Denotes that a space-space match is not allowed. the score of the alignment above is (-3) + 5 + 5 + (-2) + (-3) + 5 + (-3) + 5 = 9.

Of course, incluother alignments are possible. One is shown below (a different number of spaces are inserted into different positions ):

AGTGATG
GTTA-G

This alignment gives a score of (-3) + 5 + 5 + (-2) + 5 + (-1) + 5 = 14. so, this one is better than the previous one. as a matter of fact, this one is optimal since no other alignment can have a higher score. so, it is said that
Similarity of the two genes is 14.
Input
The input consists of T test cases. the number of test cases) (T is given in the first line of the input file. each test case consists of two lines: each line contains an integer, the length of a gene, followed by a gene sequence. the length of each gene sequence is at least one and does not exceed 100.
Output
The output shoshould print the similarity of each test case, one per line.
Sample Input
2
7. AGTGATG
5. GTTAG
7. AGCTATT
9 AGCTTTAAA
Sample Output
14
21
Source
Taejon 2001
Returns the maximum similarity between two strings.
The state transition equation can be obtained by comparing and finding the largest public subsequence.
[Cpp]
# Include <iostream>
# Include <cstdlib>
# Include <stdio. h>
# Include <memory. h>
Using namespace std;
Char s1 [110];
Char s2 [110];
Int a [30] [30];
Int dp [110] [110];
Void init ()
{
A [0] [0] = 5;
A [0] ['C'-'a'] = A ['C'-'a'] [0] =-1;
A [0] ['G'-'a'] = A ['G'-'a'] [0] =-2;
A [0] ['T'-'a'] = A ['T'-'a'] [0] =-1;
A [0] ['H'-'a'] = A ['H'-'a'] [0] =-3;
A ['C'-'a'] ['G'-'a'] = A ['G'-'a'] ['C'-'a'] = -3;
A ['C'-'a'] ['T'-'a'] = A ['T'-'a'] ['C'-'a'] = -2;
A ['C'-'a'] ['H'-'a'] = A ['H'-'a'] ['C'-'a'] = -4;
A ['G'-'a'] ['T'-'a'] = A ['T'-'a'] ['G'-'a'] = -2;
A ['G'-'a'] ['H'-'a'] = A ['H'-'a'] ['G'-'a'] = -2;
A ['T'-'a'] ['H'-'a'] = A ['H'-'a'] ['T'-'a'] = -1;
A ['C'-'a'] ['C'-'a'] = A ['G'-'a'] ['G'-'a'] = a ['T'-'a'] ['T'-'a'] = 5;
}
Int main ()
{
Int t;
Int n1, n2;
Init ();
Scanf ("% d", & t );
While (t --)
{
Scanf ("% d", & n1 );
Scanf ("% s", s1 );
Scanf ("% d", & n2 );
Scanf ("% s", s2 );
For (int I = 0; I <= n1; I ++)
For (int j = 0; j <= n2; j ++)
Dp [I] [j] =-100000000; // a negative number exists in the array
Dp [0] [0] = 0;
For (int I = 1; I <= n1; I ++)
Dp [I] [0] = dp [I-1] [0] + a [s1 [I-1]-'a'] ['H'-'a'];
For (int j = 1; j <= n2; j ++)
Dp [0] [j] = dp [0] [J-1] + a ['H'-'a'] [s2 [J-1]-'a'];
For (int I = 1; I <= n1; I ++)
For (int j = 1; j <= n2; j ++)
{
Dp [I] [j] = max (dp [I-1] [J-1] + a [s1 [I-1]-'a'] [s2 [J-1]-'a'], dp [I] [j]);
Dp [I] [j] = max (dp [I] [J-1] + a ['H'-'a'] [s2 [J-1]-'a'], dp [I] [j]);
Dp [I] [j] = max (dp [I-1] [j] + a [s1 [I-1]-'a'] ['H'-'a'], dp [I] [j]);
}
Cout <dp [n1] [n2] <endl;
}
}

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.