POJ 1080( LCS变形)
题目链接:
http://poj.org/problem?id=1080
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 20430 | Accepted: 11396 |
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
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变形)的更多相关文章
- hdu 1080(LCS变形)
Human Gene Functions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- 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 ...
- poj 1080 基因组(LCS)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19376 Accepted: ...
- poj 1080 zoj 1027(最长公共子序列变种)
http://poj.org/problem?id=1080 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=27 /* zoj ...
- 【POJ 1080】 Human Gene Functions
[POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...
- UVA-1625-Color Length(DP LCS变形)
Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...
- poj 1080 dp如同LCS问题
题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- Human Gene Functions POJ 1080 最长公共子序列变形
Description It is well known that a human gene can be considered as a sequence, consisting of four n ...
随机推荐
- CSS属性之border
css的border属性相信大家都不陌生了,就是给元素加个边框嘛,在不同的盒模型下,会给元素的宽高带来怎样的影响,相信大家也都很熟悉了,这里就不再赘述,只说说大家平时没有怎么留意的东西. 0.bord ...
- WDCP上传SSL证书
1.在线申请SSL证书 2.网站管理>SSL证书上传 3.将key文件直接上传,cert文件内容复制到crt文件中,再上传 4.开启https 注意:同一个域名下解析的若干域名,只能走主域名的证 ...
- Laravel 多域名共享session
在网站开发中会涉及登陆的问题,在登陆的过程中为了方便用户体验,我们需要用户在主域名登陆,在其他域名下也要保持登陆状态: 在config/session.php中: 更新网站配置缓存即可
- PHP链接mysql 出现:由于目标计算机积极拒绝,无法连接
1.PHP链接mysql 出现:由于目标计算机积极拒绝,无法连接 2.原因是mysql服务没有启动,图标呈现红色 3.启动服务即可,打开cmd,输入net start mysql即可 4.启动后,图标 ...
- ubuntu下使用g++编译时默认支持C++11 配置方法
1.只需要在源文件程序中加上如下一行代码: #pragma GCC diagnostic error "-std=c++11" 此时源文件代码如下: #pragma GCC dia ...
- 润乾V5手机报表说明文档
1.手机报表实例页面简要说明 index.jsp 是报表资源列表页面: mbReport.jsp 是报表展现页面: mbParam.jsp是参数报表展现页面: echarts.jsp是带有echart ...
- java 内存分析之堆栈空间
package Demo; public class Demo { public static void main(String[] args) { Demo demo = new Demo(); ; ...
- LeetCode题解之Add two numbers
1.题目描述 2.题目描述 题目思路可以参考合并单链表的思路,定义一个全局 进位标志,如果两个数值相加得到需要进位,则将进位标志置为1 . 3.代码 ListNode* addTwoNumbers(L ...
- Excel连接字符串在.NET中的应用
转:https://www.cnblogs.com/jaxu/archive/2011/07/29/2121022.html 介绍几种在.NET中直接连接Excel作为数据源的几种方法以及连接字符串的 ...
- 所有文章的测试Demo
Mqtt C++ Client 测试Demo https://pan.baidu.com/s/1Ue00GYv2SUd8aTquhvOW1w