题目:

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

题解:

类似于求lcs一样地dp,用f[i][j]表示第一个字符串匹配了前i个,第二个字符串匹配了前j个时的最高分数····推出dp方程:

f[i][j]=max(f[i-1][j-1]+table[a[i]][b[j]],max(f[i-1][j]+table[a[i]][4],f[i][j-1]+table[4][b[j]]));

其中table是题目中的分数表格····

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cctype>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int N=105;
const int table[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,0};
int n,m,T,a[N],b[N],f[N][N];
char s[N],t[N];
int trans(char s[],int i)
{if(s[i]=='A')  return 0;else if(s[i]=='C')  return 1;else if(s[i]=='G')  return 2;else if(s[i]=='T')  return 3;
}
int main()
{//freopen("a.in","r",stdin);scanf("%d",&T);while(T--){scanf("%d%s%d%s",&n,s+1,&m,t+1);memset(f,0,sizeof(f));for(int i=1;i<=n;i++)  a[i]=trans(s,i);for(int i=1;i<=m;i++)  b[i]=trans(t,i);for(int i=1;i<=n;i++)  f[i][0]=f[i-1][0]+table[a[i]][4];for(int i=1;i<=m;i++)  f[0][i]=f[0][i-1]+table[4][b[i]];for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)f[i][j]=max(f[i-1][j-1]+table[a[i]][b[j]],max(f[i-1][j]+table[a[i]][4],f[i][j-1]+table[4][b[j]]));cout<<f[n][m]<<endl;}return 0;
}

转载于:https://www.cnblogs.com/AseanA/p/7657730.html

刷题总结——Human Gene Functions(hdu1080)相关推荐

  1. Human Gene Functions(最长公共子序列变形题)

    [题目]:问题 B:  Human Gene Functions [来源]:点击打开链接 [解法]:这个题是最长公共子序列的变形题. 1.确定状态:状态表示显然是用二维数组表示DP[i][j]当前i和 ...

  2. 动态规划(DP),Human Gene Functions

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1027 http://poj.org/problem?id=108 ...

  3. POJ 1080 Human Gene Functions(DP:LCS)

    题意: 人类基因有两条,现在给出两个字符串,有长有短,可以在字符串中插入空格,要求对照表使两个字符串得出的相似值最大. 要点: 是LCS的变形,用dp[i][j]存储第一个字符串前i个字符与第二个字符 ...

  4. POJ - 1080 Human Gene Functions解题报告(求最长相同子序列)

    题目大意: 太长的英语,我就直接读了测试样例和题目中一些可以看的....好像是关于什么人类基因工程什么的, 腺嘌呤脱氧核糖核苷酸~ 每组测试实例给你两串由AGCT四个字母组成的字符串(每个字符串100 ...

  5. poj 1080 Human Gene Functions (最长公共子序列变形)

    题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...

  6. HDU 1080 Human Gene Functions

    DP,比较容易想到是2维DP,表示到第一个字符串的i和第二个字符串的j最大值是多少, 字符串下标的0在这里对应的i,j是1 #include<algorithm> #include< ...

  7. POJ1080 Human Gene Functions 动态规划 LCS的变形

    题意读了半年,唉,给你两串字符,然后长度不同,你能够用'-'把它们补成同样长度,补在哪里取决于得分,它会给你一个得分表,问你最大得分 跟LCS非常像的DP数组 dp[i][j]表示第一个字符串取第i个 ...

  8. 【HDU - 1080】Human Gene Functions(dp,可编辑距离类问题)

    题干: 给你两个DNA序列(长度不一定相同),你可以在其中任意位置上加入空格,使得最终他俩长度相同,最终相同长度的两个DNA序列会有个相似度比较(每个字符相对应的比较),问你如何放置这些空格使得总相似 ...

  9. POJ1080 Human Gene Functions(LCS)

    题目链接. 分析: 和 LCS 差不多. #include <iostream> #include <cstdio> #include <cstdlib> #inc ...

最新文章

  1. Python动态类和动态方法的创建和调用
  2. c++怎么输入带有空格的字符串_杭电OJ 字符串处理类部分题解
  3. C#断点续传原理与实现
  4. 中小企业上云多地域办公组网,建立高质量云上内网环境
  5. eclipse断点Source not found解决方案1,2,3
  6. linux 数据处理软件,【shell笔记文本处理|专项】Linux数据文本处理工具(2)
  7. 语音识别PPT.ppt
  8. ubuntu18.4 中 mysql5.7 全完卸载与安装
  9. idea创建gredle项目jar包无法导入
  10. Weblogic下载,安装与插件配置
  11. 爬取手机app实例:fiddler抓包爬取汽车之家
  12. 计算机无法登陆提示rpc服务器不可用,电脑提示RPC服务器不可用的解决方法
  13. linux如何使用磁盘阵列卡,Linux的RAID磁盘阵列与阵列卡
  14. P卡、worldfirst、连连跨境电商收款哪家好?
  15. python 面向对象编程;(搬家具)
  16. 抛出异常关键字throw与定义异常关键字throws
  17. 超详细编写登录注册页面(内含验证码登录)
  18. 主流自媒体推广平台有哪些 如何用自媒体引流
  19. 泰拉服务器生存模式物品修改,荒岛求生修改存档生存物品方法
  20. Java从入门到精通十七(Stream 流)

热门文章

  1. command对象提供的3个execute方法是_Python:3分钟看懂,基于 Psycopg2 的 PostgreSQL 操作指南!
  2. php代码里面的居中,css代码如何居中
  3. 【软考】软考简易版知识点复习指南汇总
  4. 【特别版】计算机哲学对学习生活借鉴的几个例子
  5. java页面分页显示代码_通用分页jsp页面显示
  6. mysql 记录为叶子结点,MySQL---索引
  7. wps 插件_【追加功能】OFFICE插件管理工具重整后再上路,更好用易用。
  8. JavaScript文档对象模型DOM节点操作之父节点和子节点(2)
  9. 怎么区分zh和ch_zh,ch,sh,和z,c,s怎么分辨?
  10. 数组去重实现的方式(越多越好)