题目:

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. kubernetes-jenkins CI/CD平台

    软件环境:Jenkins + Kubernetes + Git + Maven + Harbor 发布流程设计 工作流程:手动/自动构建-> Jenkins 调度K8S API->动态生成 ...

  2. QT+event() + 事件过滤器

    其存在的意义: mywidget.h: #ifndef MYWIDGET_H #define MYWIDGET_H #include <QWidget> namespace Ui { cl ...

  3. JQuery EasyUI学习记录(四)

    1.EasyUI中的validatebox使用 提供的校验规则: 1.非空校验required="required" 2.使用validType指定 email: 正则表达式匹配电 ...

  4. Bootstrap历练实例:带表格的面板

    带表格的面板 为了在面板中创建一个无边框的表格,我们可以在面板中使用 class .table.假设有个 <div> 包含 .panel-body,我们可以向表格的顶部添加额外的边框用来分 ...

  5. 《effective c++》问题总结

    04 确定对象被使用前已先被初始化 1.static/heap/stack对象 2.trivial对象 3.模板隐式具现化 implicit template instantiations 4.Sin ...

  6. STL容器之Array[转]

    转自https://blog.csdn.net/sin_geek/article/details/51067874 作者 Sin_Geek 简介 array在头文件<array> 中定义 ...

  7. 【AC自动机】bzoj3172: [Tjoi2013]单词

    fail图上后缀和需要注意一下 Description 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次. Input 第一个一个整 ...

  8. Linux - NodeJS安装

    1> 去NodeJS官网 https://nodejs.org/en/ 或 中文网 http://nodejs.cn/download/ 拷贝相应版本的安装文件,如下图: 2> 执行 wg ...

  9. MySql常用数据操作

    1.数据库操作: MySQL服务管理命令: 1.启动服务:sudo service mysql start 2.停止服务:sudo service mysql stop 3.重新启动服务:sudo s ...

  10. python入门:求1-2+3-4+5...99的所有数的和(自写)

    #!/usr/bin/env pyhton # -*- coding:utf-8 -*- #求1-2+3-4+5...99的所有数的和(自写) """ 给x赋值为0,给y ...