Human Gene Functions
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 18007 |
|
Accepted: 10012 |
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
Test instructions: Each pair of characters has its own score, you can add '-' characters to find the maximum score.
idea: Set up a dp[i][j] array that represents the str1 of the first character of the str2, the maximum fraction of the first J-character. Then Dp[n][m] is the maximum value required.
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Stdlib.h>using namespace Std;int n,m;int map[301][301];int dp[110][110];char str1[110];char str2[110];void init () { map[' A ' [' A ']=5;map[' C '] [' C ']=5;map[' g '] [' g ']=5;map[' t ' [' t ']=5;map['-'] ['-']=-1000;map[' a ' [' C ']=map[' C '] [' A ' ]=-1;map[' A ' [' G ']=map[' g '] [' A ']=-2;map[' a '] [' t ']=map[' t ' [' A ']=-1;map[' a '] ['-']=map['-'] [' A ']=-3;map[' C '] [' G ' ]=map[' g ' [' C ']=-3;map[' C '] [' t ']=map[' t ' [' C ']=-2;map[' C '] ['-']=map['-' [' C ']=-4;map[' G '] [' t ']=map[' t '] [' G ']=- 2;map[' g ' ['-']=map['-' [' g ']=-2;map[' t '] ['-']=map['-' [' t ']=-1;} int Maxx (int a,int b,int c) {a = Max (A, b); A = max (a,c); return A;} int main () {int T; Init (); scanf ("%d", &t); while (t--) {scanf ("%d%s", &N,STR1); scanf ("%d%s", &M,STR2); Dp[0][0] = 0; for (int i=1;i<=n;i++) {dp[i][0] = dp[i-1][0] + map[str1[i-1]]['-']; } for (int j=1;j<=m;j++) {Dp[0][j] = dp[0][j-1] + map['-'][str2[j-1]]; } for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {int amax = Dp[i ][J-1] + map['-'][str2[j-1]; int Bmax = dp[i-1][j] + map[str1[i-1]]['-']; int Cmax = dp[i-1][j-1] + map[str1[i-1]][str2[j-1]; DP[I][J] = Maxx (Amax,bmax,cmax); }} printf ("%d\n", Dp[n][m]); } return 0;}
Copyright NOTICE: This article is the original blogger article, if you have special needs, please contact Bo Master qq:793977586.
POJ Human Gene Functions (DP)