题目链接:

http://poj.org/problem?id=1080

Human Gene Functions
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 20430   Accepted: 11396

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 file. 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

Source

 
分析:

LCS变形题

状态转移方程如下:

j=0    ------>   dp[i][0]=dp[i-1][0]+T[f(a[i])][f('-')];

i=0    ------>  dp[0][j]=dp[0][j-1]+T[f(b[j])][f('-')];

i!=0 and j!=0  ----->   dp[i][j]=max( dp[i-1][j-1]+T[f(a[i])][f(b[j])],dp[i-1][j]+T[f(a[i])][f('-')],dp[i][j-1]+T[f(b[j])][f('-')])

ps:T代表ATCG序列对对应的值表,f函数是识别字符返回数组下标的函数

代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
int dp[][];
char a[],b[]; int f(char x)
{
if(x=='A')
return ;
if (x=='C')
return ;
if(x=='G')
return ;
if(x=='T')
return ;
if(x=='-')
return ;
}
int main()
{
int T[][]= {
{,-,-,-,-},
{-,,-,-,-},
{-,-,,-,-},
{-,-,-,,-},
{-,-,-,-,-}};
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d",&n);
getchar();
scanf("%s",a+); scanf("%d",&m);
getchar();
scanf("%s",b+);
memset(dp,,sizeof(dp)); for(int i=; i<=n; i++)
{
dp[i][]=dp[i-][]+T[f(a[i])][f('-')];
}
for(int j=; j<=m; j++)
{
dp[][j]=dp[][j-]+T[f(b[j])][f('-')];
} for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
dp[i][j]=max( dp[i-][j-]+T[f(a[i])][f(b[j])],
max(dp[i-][j]+T[f(a[i])][f('-')],
dp[i][j-]+T[f(b[j])][f('-')]));
}
}
printf("%d\n",dp[n][m]);
}
return ;
}

POJ 1080( LCS变形)的更多相关文章

  1. hdu 1080(LCS变形)

    Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. poj 1080 (LCS变形)

    Human Gene Functions 题意: LCS: 设dp[i][j]为前i,j的最长公共序列长度: dp[i][j] = dp[i-1][j-1]+1;(a[i] == b[j]) dp[i ...

  3. poj 1080 基因组(LCS)

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

  4. poj 1080 zoj 1027(最长公共子序列变种)

    http://poj.org/problem?id=1080 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=27 /* zoj ...

  5. 【POJ 1080】 Human Gene Functions

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

  6. UVA-1625-Color Length(DP LCS变形)

    Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...

  7. poj 1080 dp如同LCS问题

    题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...

  8. poj 1080 Human Gene Functions(lcs,较难)

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

  9. Human Gene Functions POJ 1080 最长公共子序列变形

    Description It is well known that a human gene can be considered as a sequence, consisting of four n ...

随机推荐

  1. 转 mysqli 事务常用方法

    原文:mysqli 事务常用方法 1. //打开(true)或关闭(false)本次数据库连接的自动命令提交事务模式 //参数如果设置为 FALSE,则表示关闭 auto-commit.如果设置为 T ...

  2. opencv3.2.0形态学滤波之开运算、闭运算

    /* 一.开运算: (1)开运算,其实就是先腐蚀后膨胀的过程. (2)数学表达式:dst = open(src,element) = dilate(erode(src,element)) (3)作用: ...

  3. Git Client 管理:项目文件的获取和提交(实用篇)

    Git 服务器 可搭在云端如:coding.net.GitHub.TFS等,只要可以使用Git就可以. 示例: Git Client 安装相关程序,顺序如下: 1.安装Git-2.14.2.3-64- ...

  4. 润乾报表新功能–导出excel支持锁定表头

     在以往的报表设计中,锁定表头是会经常被用到的一个功能,这个功能不仅能使浏览的页面更加直观,信息对应的更加准确,而且也提高了报表的美观程度.但是,很多客户在将这样的报表导出excel时发现exce ...

  5. onInterceptTouchEvent与onTouchEvent默认返回值

    其中Layout里的onInterceptTouchEvent默认返回值是false,这样touch事件会传递到View控件,Layout里的onTouch默认返回值是false, View里的onT ...

  6. mysql 命令行查看数据库、创建数据库、选择数据库、删除数据库

    mysql数据库命名规则(标识符规则): 不能和已存在的命名重名: 由大小写字母.数据.下划线.@.# 和 $ 符号组成: 首字母不能是数字和$符. 不允许有空格和特殊字符. 不允许是mysql的保留 ...

  7. Oracle EBS 应收API只创建收款没有核销行以及消息堆栈

    只创建了收款但没有创建核销行 排除其他原因 有可能是缓存溢出导致的这个要改成true 且使用消息堆栈处理

  8. SQL Server ->> 使用CROSS APPLY语句是遇到聚合函数中包含外部引用列时报错

    本次遇到的问题是CROSS APPLY的内部查询语句中的聚合函数包含CASE WHEN判断,且同时又内部语句的表的列和外部引用的表的列,此时会报下列的错误. 消息 8124,级别 16,状态 1,第 ...

  9. sql server 查询ntext字段长度

    DATALENGTH 返回任何表达式所占用的字节数. 语法 DATALENGTH ( expression ) 参数 expression 任何类型的表达式. 返回类型 int 注释 DATALENG ...

  10. linux下指定源下载

    我们默认使用yun  安装的时候 使用的 是外国的网站进行下载的  那么下载肯定是慢的 我们可以更改为国内的站点进行下载的 比如临时更改为国内的站点进行下载 pip install -i +你的源 p ...