POJ Human Gene Functions DP

Source: Internet
Author: User

Human Gene Functions
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 18028 Accepted: 10027

Description

It's well known a human gene can considered as a sequence, consisting of four nucleotides, which was simply Denot Ed by four letters, A, C, G, and T. Biologists has been interested in identifying human genes and determining their funct Ions, because these can be used to diagnose human diseases and to design new drugs for them.

A human gene can 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 was to determine its function.
One of the methods for biologists to use in determining the function of a new gene sequence that they has just identified IS-search a database with the new gene as a query. The database to is searched stores many gene sequences and their functions–many researchers have been submitting their g Enes and functions to the database and the database are freely accessible through the Internet.

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

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

For example, one space was inserted into AGTGATG to the result in agtgat-g, and three spaces was inserted into gttag to result In–gt--tag. A space is denoted by a minus sign (-). The genes is now of equal
Length. These strings is aligned:

Agtgat-g
-gt--tag

In this alignment, there is 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 are assigned a score according to the following scoring matrix.

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

Of course, many other alignments is possible. One is shown below (a different number of spaces be 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 was optimal since no other alignment can has a higher score. So, it's said that
Similarity of the 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 Lines:each line contains a integer, the length of a gene, followed by a gene sequence. The length of each gene sequence are at least one and does not exceed 100.

Output

The output should print the similarity of each test case, one per line.

Sample Input

Sample Output

Source

Taejon 2001

I and J write mixed WA once sweat

AC Code:

#include <iostream> #include <cstring>using namespace Std;int sorce[5][5]={{0,-3,-4,-2,-1},{-3,5,-1,-2,-    1},{-4,-1,5,-3,-2},{-2,-2,-3,5,-2},{-1,-1,-2,-2,5}};int Main () {int loop;    cin>>loop;    String A, B;    int la,lb;    int i,j;    int dp[110][110];    char c;        while (loop--) {int sa[111],sb[111];        cin>>la;            for (i=0;i<la;++i) {cin>>c;            if (c== ' A ') sa[i]=1;            if (c== ' C ') sa[i]=2;            if (c== ' G ') sa[i]=3;        if (c== ' T ') sa[i]=4;        } sa[la]=0;        cin>>lb;            for (i=0;i<lb;++i) {cin>>c;            if (c== ' A ') sb[i]=1;            if (c== ' C ') sb[i]=2;            if (c== ' G ') sb[i]=3;        if (c== ' T ') sb[i]=4;        } sb[lb]=0;        Memset (Dp,0,sizeof (DP));        for (I=1;i<=la+1;++i) dp[i][0]=dp[i-1][0]+sorce[0][sa[i-1]];        for (I=1;i<=lb+1;++i) dp[0][i]=dp[0][i-1]+sorce[0][sb[i-1]]; for (I=1;i<=la+1;++i) {for (j=1;j< =lb+1;++j) {Dp[i][j]=max (Dp[i-1][j]+sorce[0][sa[i-1]],max (dp[i][j-1]+sorce[0][sb[j-1]],dp[i-1][j-1]+sorce[                SA[I-1]][SB[J-1]));        }} I=max (Dp[la][lb],max (dp[la][lb+1],dp[la+1][lb]));    cout<<i<< ' \12 '; } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ Human Gene Functions DP

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.