Human Gene Functions

来源:互联网 发布:手机休眠关闭网络 编辑:程序博客网 时间:2024/04/30 09:38

http://acm.hdu.edu.cn/showproblem.php?pid=1080

Problem 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. 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
 &&&&&&&&&&&&&&&&&
以第一个为例:
初始化:第一行是长度为5的字符串全部匹配' '的时候的最大值,同理竖着的一行是长度为7的字符串全部匹配为' '的时候的最大值;
0 -2 -3 -4 -7 -9
-3 0 0 0 0 0
-5 0 0 0 0 0
-6 0 0 0 0 0
-8 0 0 0 0 0
-11 0 0 0 0 0
-12 0 0 0 0 0
-14 0 0 0 0 0
接着对其处理;(长度为5)第i个字母,要么与(长度为7)第j个字母匹配;要么匹配空格;
0 -2 -3 -4 -7 -9
-3 -2 -3 -4 1 -1
-5 2 1 0 -1 6
-6 1 7 6 3 5
-8 -1 5 5 4 8
-11 -4 2 4 10 8
-12 -5 1 7 9 8
-14 -7 -1 5 7 14

#include<stdio.h>#include<iostream>#include<string.h>using namespace std;int map[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,INT_MIN}};int MAX(int a,int b,int c){int tmp=a>b?a:b;return tmp>c?tmp:c;}char s1[200],s2[200];int dp[200][200];int main(){int i,j,k,m,n,ncase;scanf("%d",&ncase);int t[256];t['A']=0;t['C']=1;t['G']=2;t['T']=3;t[' ']=4;while(ncase--){scanf("%d %s",&m,s1);scanf("%d %s",&n,s2);//printf("s1==%s s2==%s\n",s1,s2);dp[0][0]=0;for(i=1;i<=n;i++){   dp[0][i]=dp[0][i-1]+map[4][t[s2[i-1]]];   //printf("dp[0][%d]==%d ",i,dp[0][i]);}//printf("\n");for(i=1;i<=m;i++){    dp[i][0]=dp[i-1][0]+map[4][t[s1[i-1]]];    //printf("dp[%d][0]==%d ",i,dp[i][0]);}/*for(i=0;i<=m;i++){for(j=0;j<=n;j++){printf("%d ",dp[i][j]);}printf("\n");}*/for(i=1;i<=m;i++){for(j=1;j<=n;j++){int m1=dp[i-1][j-1]+map[t[s1[i-1]]][t[s2[j-1]]];int m2=dp[i-1][j]+map[t[s1[i-1]]][4];int m3=dp[i][j-1]+map[t[s2[j-1]]][4];int m4=MAX(m1,m2,m3);dp[i][j]=m4;}}/*for(i=0;i<=m;i++){for(j=0;j<n;j++){printf("%d ",dp[i][j]);}puts("");}*/printf("%d\n",dp[m][n]);}return 0;}




原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 三星手机外屏碎了怎么办 苹果手机外屏碎了怎么办 iphone6s听筒坏了怎么办 苹果x外屏碎了怎么办 苹果手机屏摔坏了怎么办 苹果8外屏摔碎了怎么办 苹果7内屏坏了怎么办 苹果手机屏幕里面有水痕怎么办 iphone6屏幕摔裂怎么办 苹果手机电池坏了怎么办 苹果手机充电器坏了怎么办 苹果充电器老是坏怎么办 苹果手机屏幕失控了怎么办 手机自己乱点怎么办 手机点屏幕没用怎么办 手机界面不动了怎么办 手机关不了机怎么办 小米5花屏怎么办 小米手机死机怎么办呢 手机触屏失灵怎么办? 手机触屏不行怎么办 苹果手机屏幕触摸失灵怎么办 苹果7按键失灵怎么办 苹果中间键失灵怎么办 苹果屏触摸不灵怎么办 ipad屏幕乱跳怎么办 屏幕自己乱点怎么办 手机触屏漂移怎么办 玩不好飘频怎么办 苹果手机城乱码了怎么办 苹果手机屏幕乱跳怎么办 苹果笔记本键盘乱码怎么办 苹果电脑打开word乱码怎么办 iphone5s屏幕竖纹怎么办 电脑显示跳屏怎么办 电脑显示器跳屏怎么办 ipad老是跳屏怎么办 lol一直跳ping怎么办 电脑图标一直闪怎么办 vivo手机跳屏怎么办 手机跳屏怎么办oppo