Human Gene Functions
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3008 Accepted Submission (s): 1701
Problem DescriptionIt is well known the A human gene can be considered as a sequence, consisting of four nucleotides, whi CH is simply denoted by four letters, A, C, G, and T. Biologists has been interested in identifying human genes and dete Rmining their functions, 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 both genes is called alignment. In an alignment, spaces is inserted, if necessary, in appropriate positions of the genes-make them equally long and SC Ore 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 the similarity of the the genes is 14.
Inputthe input consists of T test cases. The number of test cases) (T is given in the first line of the input. 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.
Outputthe output should print the similarity of each test case, one per line.
Sample Input2 7 AGTGATG 5 gttag 7 Agctatt 9 agctttaaa
Sample Output14 21
Source Test instructions: give you two strings, ask where to add how many-number can make the weight of the largest. Analysis: Same as LCS. Divided into three states to consider: In the afternoon training, the state equation came out of the initialization has never thought of the answer, no longer think of this problem. Let's make a note of it today.
#include <stdio.h>#include<algorithm>#include<string.h>#include<iostream>#defineN 105using namespacestd;intmp[5][5]={ {5,-1,-2,-1,-3}, {-1,5,-3,-2,-4}, {-2,-3,5,-2,-2}, {-1,-2,-2,5,-1}, {-3,-4,-2,-1,100000}};intDp[n][n];intMain () {inttcase; scanf ("%d",&tcase); while(tcase--) { intn,m; Charstr1[ the],str2[ the]; scanf ("%d%s", &n,str1+1); scanf ("%d%s", &m,str2+1); Memset (DP,0,sizeof(DP)); intx, y; for(intI=1; i<=n; i++)///It 's important here . { if(str1[i]=='A') y=0; if(str1[i]=='C') y=1; if(str1[i]=='G') y=2; if(str1[i]=='T') y=3; dp[i][0] = dp[i-1][0] + mp[y][4]; } for(intI=1; i<=m; i++) { if(str2[i]=='A') x=0; if(str2[i]=='C') x=1; if(str2[i]=='G') x=2; if(str2[i]=='T') x=3; dp[0][i] = dp[0][i-1] + mp[4][x]; } for(intI=1; i<=n; i++) { for(intj=1; j<=m; J + +) { if(str1[i]=='A') x=0; if(str1[i]=='C') x=1; if(str1[i]=='G') x=2; if(str1[i]=='T') x=3; if(str2[j]=='A') y=0; if(str2[j]=='C') y=1; if(str2[j]=='G') y=2; if(str2[j]=='T') y=3; DP[I][J]= Max (dp[i-1][j-1]+mp[x][y],max (dp[i-1][j]+mp[4][x],dp[i][j-1]+mp[4][y])); } } //for (int i=1;i<=n;i++)printf"%d\n", Dp[n][m]); } return 0;}
HDU (LCS variant)