您的位置:首页 > 其它

poj 1080 Human Gene Functions

2016-08-13 16:12 483 查看
Human Gene Functions

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 18960 Accepted: 10564
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 an efficient 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


提示

题意:

题目太长这里简化以下。。。

给出两个字符串以及它们的长度,求出添加'-'号使得它们长度相等且保证值为最大的方案。

以第一组数据为例:

我们在第二个较短的字符串上添加'-'号,产生:

AGTGATG
GTTA-G
对应表它们的值为(-3)+5+5+(-2)+5+(-1) +5=14



AGTGATG
-GTTAG
(-3)+(-2)+(-2)+(-2)+(-1)+(-1)+5=-6

显然第一种最大。('-'号与'-'号是不存在对应关系)

思路:

类似于求最长公共子序列,但并不能直接在这题上使用。似乎不需要考虑添加'-'号后会超过最长字符串的长度,下面给出递推式:

第一种情况:dp[i-1][i1]+a[Ci]['-']。在第一个字符串上加'-'号。(这里的Ci表示第一个字符串字符,a[Ci][4]是字符所对应的数值)

第二种情况:dp[i][i1-1]+a['-'][Ci1]。在第二个字符串上加'-'号。(这里的Ci1表示第二个字符串字符)

第三种情况:dp[i-1][i1-1]+a[Ci][Ci1]。不加'-'号。

dp[i][i1]=上述三种情况最大值。

至于过程,就交给你了。(我不擅长讲DP题啊)


示例程序

Source Code

Problem: 1080		Code Length: 1184B
Memory: 392K		Time: 0MS
Language: GCC		Result: Accepted
#include <stdio.h>
char f(char c)						//转化函数(直接用ASCii码值)
{
if(c=='A')
{
return 0;
}
else if(c=='C')
{
return 1;
}
else if(c=='G')
{
return 2;
}
else if(c=='T')
{
return 3;
}
}
int max(int a,int b)
{
if(a>b)
{
return a;
}
else
{
return b;
}
}
int main()
{
int t,n,m,i,i1,i2,dp[101][101],a[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,-900}};
char ch[101],ch1[101];			//a数组手动打表
scanf("%d",&t);
for(i=1;t>=i;i++)
{
scanf("%d %s",&n,ch);
dp[0][0]=0;
for(i1=0;n>i1;i1++)
{
ch[i1]=f(ch[i1]);					//字母转化
dp[i1+1][0]=dp[i1][0]+a[ch[i1]][4];			//初始化全部是'-'
}
scanf("%d %s",&m,ch1);
for(i1=0;m>i1;i1++)
{
ch1[i1]=f(ch1[i1]);					//字母转化
dp[0][i1+1]=dp[0][i1]+a[4][ch1[i1]];		//初始化全部是'-'
}
for(i1=0;n>i1;i1++)		//因为字符数组下标从0开始,dp数组运算时为了一致采用了i1+1,i2+1的方式
{
for(i2=0;m>i2;i2++)
{
dp[i1+1][i2+1]=max(max(dp[i1+1][i2]+a[4][ch1[i2]],dp[i1][i2+1]+a[ch[i1]][4]),dp[i1][i2]+a[ch[i1]][ch1[i2]]);
}				//这里是当前状态=max(max(第一种情况,第二种情况),第三种情况)
}
printf("%d\n",dp
[m]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: