题目:

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=;
const int table[][]={,-,-,-,-,
-,,-,-,-,
-,-,,-,-,
-,-,-,,-,
-,-,-,-,};
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 ;
else if(s[i]=='C') return ;
else if(s[i]=='G') return ;
else if(s[i]=='T') return ;
}
int main()
{
//freopen("a.in","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%d%s%d%s",&n,s+,&m,t+);memset(f,,sizeof(f));
for(int i=;i<=n;i++) a[i]=trans(s,i);
for(int i=;i<=m;i++) b[i]=trans(t,i);
for(int i=;i<=n;i++) f[i][]=f[i-][]+table[a[i]][];
for(int i=;i<=m;i++) f[][i]=f[][i-]+table[][b[i]];
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
f[i][j]=max(f[i-][j-]+table[a[i]][b[j]],max(f[i-][j]+table[a[i]][],f[i][j-]+table[][b[j]]));
cout<<f[n][m]<<endl;
}
return ;
}

刷题总结——Human Gene Functions(hdu1080)的更多相关文章

  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(lcs,较难)

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

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

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

  5. Human Gene Functions

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

  6. 【POJ 1080】 Human Gene Functions

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

  7. 杭电20题 Human Gene Functions

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

  8. poj1080 - Human Gene Functions (dp)

    题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...

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

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

随机推荐

  1. Python2 和Python3 的区别

    print Python 2中的print语句被Python 3中的print()函数取代,这意味着在Python 3中必须用括号将需要输出的对象括起来. 在Python 2中使用额外的括号也是可以的 ...

  2. PAT (Basic Level) Practise (中文)- 1007. 素数对猜想 (20)

    http://www.patest.cn/contests/pat-b-practise/1007 让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数.显然有 d1=1 且对 ...

  3. iOS开发-动画总结

    一.简介 IOS 动画主要是指Core Animation框架.官方使用文档地址为:Core Animation Guide.Core Animation是IOS和OS X平台上负责图形渲染与动画的基 ...

  4. SpringMVC 项目中引用其他 Module 中的方法

    1. 将要引用的Module 引入项目中 2. 在主Module中添加依赖, 3. 被引用的类必须放在 Module 中/src/下的某个package中,否则引用不到(重要)

  5. 最长公共子序列(LCS)问题

    最长公共子串(Longest Common Substirng)和最长公共子序列(Longest Common Subsequence,LCS)的区别为:子串是串的一个连续的部分,子序列则是从不改变序 ...

  6. 如何生成带注释的DLL文件

    背景: 实际上并不是生成带有注释的DLL文件,而是同时生成一个XML文件,用来显示注释. 为什么要使用DLL文件,在C#编程的过程中,一直在使用DLL文件,如System.dll 方法: 1,创建类库 ...

  7. 设置ubuntu12.04的dasher-自动隐藏,左上角

    点击右上角的齿轮,--> “system setting”--“Appearance” 在“Look”标签中: Theme:Ambiance Launch icon size :32 选择桌面背 ...

  8. BZOJ 5215: [Lydsy2017省队十连测]商店购物

    裸题 注意+特判 #include<cstdio> using namespace std; const int mod=1e9+7; int F[1000005],mi[10000005 ...

  9. Ubuntu简单指令和热键的学习

    Ubuntu查看本机版本的方法 sudo lsb_release -a即可 注销linux: 输入:exit 注意,离开系统不是关机,基本上,linux本身已经有相当多的工作进行,所以你离开时,这次这 ...

  10. SVR回归

    1.python支持向量机回归svr预测 https://blog.csdn.net/u012581541/article/details/51181041 https://www.cnblogs.c ...