Human Gene Functions

Time Limit: 1000MS Memory Limit: 10000K

Total Submissions: 18053 Accepted: 10046

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

求DNA匹配度,类似最长公共子序列

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
using namespace std; typedef long long LL; typedef pair<int,int>p; const int INF = 0x3f3f3f3f; int value[][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,0}}; map<char ,int >Dir; int lens,lenc; int Dp[110][110]; int main()
{
int n;
char s[110];
char c[110];
Dir['A']=0;
Dir['C']=1;
Dir['G']=2;
Dir['T']=3;
Dir['-']=4;
while(~scanf("%d",&n))
{
while(n--)
{
scanf("%d %s",&lens,s+1);
scanf("%d %s",&lenc,c+1);
Dp[0][0]=0;
for(int i=1;i<=lens;i++)
{
Dp[i][0]=Dp[i-1][0]+value[Dir[s[i]]][Dir['-']];//如果都不匹配的情况
}
for(int i=1;i<=lenc;i++)
{
Dp[0][i]=Dp[0][i-1]+value[Dir[c[i]]][Dir['-']];
}
for(int i=1;i<=lens;i++)
{
for(int j=1;j<=lenc;j++)
{
Dp[i][j]=Dp[i-1][j-1]+value[Dir[s[i]]][Dir[c[j]]];//如果两个字符要匹配,则Dp[i][j]由Dp[i-1][j-1]推出.
Dp[i][j]=max(Dp[i][j],Dp[i-1][j]+value[Dir[s[i]]][Dir['-']]);//前面的字符与这个已经匹配(不管用什么方式匹配的),他只能与'-'匹配
Dp[i][j]=max(Dp[i][j],Dp[i][j-1]+value[Dir['-']][Dir[c[j]]]);//如果这个字符已经与前面匹配,则c[j]与'-'匹配
}
}
printf("%d\n",Dp[lens][lenc]);
}
}
return 0;
}

Human Gene Functions的更多相关文章

  1. hdu1080 Human Gene Functions() 2016-05-24 14:43 65人阅读 评论(0) 收藏

    Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17805   Accepted:  ...

  3. 【POJ 1080】 Human Gene Functions

    [POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...

  4. poj 1080 Human Gene Functions(lcs,较难)

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19573   Accepted:  ...

  5. POJ 1080:Human Gene Functions LCS经典DP

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18007   Accepted:  ...

  6. POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)

    题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...

  7. 杭电20题 Human Gene Functions

    Problem Description It is well known that a human gene can be considered as a sequence, consisting o ...

  8. 刷题总结——Human Gene Functions(hdu1080)

    题目: Problem Description It is well known that a human gene can be considered as a sequence, consisti ...

  9. Human Gene Functions POJ 1080 最长公共子序列变形

    Description It is well known that a human gene can be considered as a sequence, consisting of four n ...

随机推荐

  1. [原创]java WEB学习笔记71:Struts2 学习之路-- struts2常见的内建验证程序及注意点,短路验证,非字段验证,错误消息的重用

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  2. wamp多站点配置

    1.修改wamp安装目录下:\wamp\bin\apache\Apache2.2.21\conf\extra中的httpd-vhosts.conf文件如下: 2.修改wamp-apache-httpd ...

  3. <c:if>标签的使用

    <c:if>标签用来在页面中实现条件化的判断功能.它的主要目的就是替换Java脚本中的if语句,来实现页面内容的条件化输出功能.这个标签所进行的判读主要是依据表达式来进行的,如果该表达式的 ...

  4. HDU 4512 吉哥系列故事——完美队形(LCIS)

    Problem Description 吉哥这几天对队形比较感兴趣. 有一天,有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一 ...

  5. PHP浮点数的一个常见问题的解答 (转载 http://www.laruence.com/2013/03/26/2884.html)

    不过, 我当时遗漏了一点, 也就是对于如下的这个常见问题的回答: <?php $f = 0.58; var_dump(intval($f * 100)); //为啥输出57 ?> 为啥输出 ...

  6. Axis2、Axis1 以及其他接口的调用方式

    在请求的时候出现问题,使用下面的方式请求就不会出现问题. package webservice.client.utils; import java.util.Iterator; import java ...

  7. json转化为java实体

    import net.sf.json.JSONObject; Map<String, Object> classMap = new HashMap<String, Object> ...

  8. beta阶段事后诸葛亮会议

    项目名:约跑 组名:nice! 组长:李权 组员: 韩媛媛 于淼 刘芳芳 宫丽君 Beta Review会议 时间:2016.11.15 地点:冬华楼一楼大厅 会议内容: 约跑APP的Beta Rev ...

  9. 关于archlinux下的ralink5370网卡

    驱动此网卡要使用 rt2800usb,rt2800lib 这两个模块 顺便说一下对模块进行操作的命令: rmmod 模块名 //为移除模块 insmod 模块所在路径 //为添加模块 查看网卡是否能被 ...

  10. 由 "select *" 引发的“惨案”

    今天凌晨做发布, 要合并多个分数据库的表数据到主数据库中, 有 30+ 分数据库. 前面都比较顺利, 在临近结束时,突然发现一个字段的值插入错误. 有一个表 T,字段分别为 (f1, f2, f3, ...