POJ-1080-Human Gene Functions
2016-08-25 09:33
288 查看
Human Gene Functions
It is well known that a human gene can be considered as a sequence(序列), consisting of four nucleotides(核苷), 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 many 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 anefficient(有效率的) 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 of 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 –GT--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, many other 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 the 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(输出) should 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 |
#include<iostream> #include<string.h> #include<stdio.h> #include<math.h> #include<algorithm> #include<queue> #include<vector> #include<map> using namespace std; int score['T'+1]['T'+1]; const int inf = -99999; int Max(int a, int b, int c) { if(a>=b&&a>=c)return a; else if(b>=a&&b>=c)return b; return c; } void initial() { score['A']['A']=5; score['C']['C']=5; score['G']['G']=5; score['T']['T']=5; score['-']['-']=inf; score['A']['C']=score['C']['A']=-1; score['A']['G']=score['G']['A']=-2; score['A']['T']=score['T']['A']=-1; score['A']['-']=score['-']['A']=-3; score['C']['G']=score['G']['C']=-3; score['C']['T']=score['T']['C']=-2; score['C']['-']=score['-']['C']=-4; score['G']['T']=score['T']['G']=-2; score['G']['-']=score['-']['G']=-2; score['T']['-']=score['-']['T']=-1; return; } int main() { initial(); int t, n, m, dp[110][110]; char s1[ 110], s2[110]; scanf("%d",&t); while(t--) { scanf("%d%s%d%s", &n, s1, &m, s2); memset(dp, 0, sizeof(dp)); for(int i = 1;i<=n;++i) dp[i][0] = dp[i-1][0]+score[s1[i-1]]['-']; for(int j = 1; j<=m;++j) dp[0][j] = dp[0][j-1]+score['-'][s2[j-1]]; for(int i = 1; i<=n;++i) { for(int j = 1; j<=m;++j)//三种情况取最大值 { int a = dp[i-1][j-1]+score[s1[i-1]][s2[j-1]]; int b = dp[i-1][j]+score[s1[i-1]]['-']; int c = dp[i][j-1]+score['-'][s2[j-1]]; dp[i][j] = Max(a, b, c); } } printf("%d\n", dp [m]); } return 0; }
相关文章推荐
- POJ 1080 Human Gene Functions
- poj 1080 Human Gene Functions(动态规划)
- POJ 1080 Human Gene Functions
- Human Gene Functions(poj 1080)
- poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions(LCS变形)
- poj 1080 Human Gene Functions
- hdu 1080 ;poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- poj 1080 Human Gene Functions(dp)
- (字符串的处理方式4.7.15)POJ 1080 Human Gene Functions(两个字符串的最佳匹配)
- 【POJ 1080】 Human Gene Functions
- POJ 1080 Human Gene Functions(LCS)
- POJ-1080-Human Gene Functions-LCS变体,动态规划,DP
- POJ 1080 Human Gene Functions
- poj-1080 Human Gene Functions **
- POJ 1080 Human Gene Functions 已被翻译
- POJ 1080 Human Gene Functions(LCS变形)
- POJ_1080_Human Gene Functions
- 【dp】POJ - 1080 Human Gene Functions