poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 17805 | Accepted: 9917 |
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
2
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA
Sample Output
14
21 可参考:http://user.qzone.qq.com/289065406/blog/1300550378
解题思路:沿用最长公共子序列的思想,同时注意边界处理。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=210;
char str1[maxn],str2[maxn];
int dp[maxn][maxn];
int Map[10][10]={
{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 ID(int x){
int ret;
switch(x){
case 'A':ret=0;break;
case 'C':ret=1;break;
case 'G':ret=2;break;
case 'T':ret=3;break;
case '-':ret=4;break;
}
return ret;
}
int mmax(int a,int b,int c){
int ret;
ret=a>b?a:b;
return ret>c?ret:c;
} int main(){
int t,n,m,i,j,k,len,d,v1,v2,v3;
scanf("%d",&t);
while(t--){
scanf("%d%s%d%s",&n,str1+1,&m,str2+1);
dp[0][0]=0;
for(i=1;i<=n;i++){
dp[i][0]=dp[i-1][0]+Map[ID(str1[i])][ID('-')];
}
for(i=1;i<=m;i++){
dp[0][i]=dp[0][i-1]+Map[ID('-')][ID(str2[i])];
}
v1=0,v2=0,v3=0;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
v1=dp[i-1][j]+Map[ID(str1[i])][ID('-')];
v2=dp[i][j-1]+Map[ID('-')][ID(str2[j])];
v3=dp[i-1][j-1]+Map[ID(str1[i])][ID(str2[j])];
dp[i][j]=mmax(v1,v2,v3);
}
}
printf("%d\n", dp[n][m]);
}
return 0;
}
poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】的更多相关文章
- poj 1080 Human Gene Functions (最长公共子序列变形)
题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...
- HDU 1080 Human Gene Functions - 最长公共子序列(变形)
传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- POJ 1080 Human Gene Functions
题意:给两个DNA序列,在这两个DNA序列中插入若干个'-',使两段序列长度相等,对应位置的两个符号的得分规则给出,求最高得分. 解法:dp.dp[i][j]表示第一个字符串s1的前i个字符和第二个字 ...
- POJ 1080 Human Gene Functions 【dp】
题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...
- P 1080 Human Gene Functions
大概作了一周,终于A了 类似于求最长公共子序列,稍有变形 当前序列 ch1 中字符为 a,序列 ch2 中字符为 b 则有 3 种配对方式: 1. a 与 b 2. a 与 - 3. - 与 b 动态 ...
随机推荐
- c# 对象反射赋值未知属性需类型转换
反射某个类时,对于类的属性,字段.已知有已知的方法,未知有未知的写法. 而SetValues赋值则需要类型转换 情况1,该属性类型是已知类型,例如:int int value=500; propert ...
- MySql8.0后密码认证方式问题[caching-sha2-password]
这个问题通常在laravel中表现为类似下边的异常: local.ERROR: SQLSTATE[HY000] [2006] MySQL server has gone away {"exc ...
- 编码原则实例------c++程序设计原理与实践(进阶篇)
编码原则: 一般原则 预处理原则 命名和布局原则 类原则 函数和表达式原则 硬实时原则 关键系统原则 (硬实时原则.关键系统原则仅用于硬实时和关键系统程序设计) (严格原则都用一个大写字母R及其编号标 ...
- 主流C语言编译器介绍
- R:魔兽世界终极版
描述 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部.两个司令部之间是依次排列的若干城市,城市从西向东依次编号为1,2,3 .... N ( N <= 20 ).红魔军的司令部算作编号为0 ...
- CF138D World of Darkraft
$ \color{#0066ff}{ 题目描述 }$ n*m的格子,每个格子有字符'L','R',X',初始可以选择所有格子. 当选了 'L'的格子时,当前格子左下右上这条线上所有点不能选; 当选了 ...
- grafana使用小节
安装准备 安装grafana 安装mysql grafana操作步骤 新建数据源,支持mysql 数据库连接失败处理: https://www.jianshu.com/p/684bc3a77ac9 新 ...
- 扩增子分析QIIME2. 1简介和安装
原网站:https://blog.csdn.net/woodcorpse/article/details/75103929 声明:本文为QIIME2官方帮助文档的中文版,由中科院遗传发育所刘永鑫博士翻 ...
- LeetCode记录之26——Remove Duplicates from Sorted Array
国外的表达思维跟咱们有很大差别,做这道题的时候很明显.简单说本题就是让你把有序数组中的重复项给换成正常有序的.比如 1 2 2 3换成 1 2 3 3,根本不需要考虑重复的怎么办,怎么删除重复项等等. ...
- logstash根据配置文件启动时,报异常
请查看你的配置文件中是否包含了特殊字符,通常,复制黏贴过来的配置文件,会带有特殊字符.这个很影响logstash的启动. linux中查看文件中的特殊字符方法: 使用cat方法 cat -A 文件名 ...