刷题总结——Human Gene Functions(hdu1080)
题目:
Problem Description
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
Output
Sample Input
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA
Sample Output
题解:
类似于求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)的更多相关文章
- 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 ...
- poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- Human Gene Functions
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...
- 【POJ 1080】 Human Gene Functions
[POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...
- 杭电20题 Human Gene Functions
Problem Description It is well known that a human gene can be considered as a sequence, consisting o ...
- poj1080 - Human Gene Functions (dp)
题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
随机推荐
- [论文理解] Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks 简介 Faster R-CNN是很经典的t ...
- 第二单元OO总结
目录 前言 一.第一次作业分析 1. UML及复杂度分析 二.第二次作业分析 1. UML及复杂度分析 2. 性能优化 2.1 楼层类的实现 2.2 调度算法 3. bug分析 三.第三次作业分析 1 ...
- RestSharp使用备忘
(1)一般调用: public static List<T> Execute<T>(string resourceUrl, object obj, out int totalN ...
- LINQ结合正则表达式查询文件系统
string startFolder = @"D:\Program Files (x86)\Microsoft Visual Studio 12.0\"; IEnumerable& ...
- 01_4_Struts路径问题
01_4_Struts路径问题 1. Struts路径问题说明 struts2中的路径问题是根据action的路径而不是jsp路径来确定,所有尽量不要使用相对路径. 虽然可以使用redirect方式解 ...
- 在线聊天项目1.4版 使用Gson方法解析Json字符串以便重构request和response的各种请求和响应 解决聊天不畅问题 Gson包下载地址
在线聊天项目结构图: 多用户登陆效果图: 多用户聊天效果图: 数据库效果图: 重新构建了Server类,使用了Gson方法,通过解析Json字符串,增加Info类,简化判断过程. Server类代码如 ...
- 协议(Protocol)与委托代理(Delegate)
协议(Protocol)的作用: 1. 规范接口,用来定义一套公用的接口: 2. 约束或筛选对象. 代理(Delegate): 它本身是一种设计模式,委托一个对象<遵守协议>去做某件事情, ...
- 【转】Windows 邮件槽(MailSlot)
Windows 邮件槽(MailSlot) 来自<Windows网络编程第二版 中文版> 优点:通过网络,将一条消息广播给一台或多台计算机. 缺点:只允许从客户机到服务器,建立一种不可 ...
- Android读书笔记二
本章讲到需要Android应用程序以及Android NDK程序来测试Linux驱动,所以所需要的工具都必须配备好.而且对工具的版本也是有一些要求,JDK,Eclipse,ADT,CDT,Androi ...
- 51nod——1548 欧姆诺姆和糖果
一开始以为是贪心,然后发现没法贪.暴力枚举肯定T,于是用约束关系优化: 假设wr >= wb, 第一种情况:wr >= sqrt (c), 则此时最多吃c / wr个r,且c / wr & ...