您的位置:首页 > 其它

POJ-1080-Human Gene Functions

2016-08-25 09:33 288 查看
Human Gene Functions

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 18886 Accepted: 10518
Description

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
dp, 类似于找最大公共字串

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: