HDU 1080 Human Gene Functions--DP--(变形最长公共子)
意甲冠军:该基因序列的两端相匹配,四种不同的核苷酸TCGA有不同的分值匹配。例如T—G比分是-2,它也可以被加入到空格,空洞格并且还具有一个相应的核苷酸匹配分值,求最大比分
分析:
在空气中的困难格的数量和位置不确定
二维dp,dp[i][j]表示序列a的前i段和序列b的前j段匹配时的最大分数。
接下来细致分析当i和j匹配的情况:1.a[i]与b[j]匹配;2.a[i]与b[j-1]。3.a[i]与b[j+1]。
所以方程:dp [i][j]= max(dp[i-1][j]+mat[i]['#'],dp[i][j-1]+mat['#'][j],dp[i-1][j-1]+mat[i][j])
代码:
#include<iostream>
#include<string>
#include<cstring>
#define INF 0x3f3f3f3f
using namespace std;
int t,n,m,dp[200][200];
string a,b;
int mat[200][200];
int max(int a,int b)
{
return a>b? a:b;
}
void f()
{
mat['A']['A']=5; mat['C']['C']=5; mat['G']['G']=5;
mat['T']['T']=5; mat['A']['C']=-1; mat['A']['G']=-2;
mat['A']['T']=-1; mat['A']['#']=-3; mat['C']['A']=-1;
mat['C']['G']=-3; mat['C']['T']=-2; mat['C']['#']=-4;
mat['G']['A']=-2; mat['G']['C']=-3; mat['G']['T']=-2;
mat['G']['#']=-2; mat['T']['A']=-1; mat['T']['C']=-2;
mat['T']['G']=-2; mat['T']['#']=-1; mat['#']['A']=-3;
mat['#']['C']=-4; mat['#']['G']=-2; mat['#']['T']=-1;
mat['#']['#']=-INF; }
int main()
{
f();
cin>>t;
while(t--){
cin>>n>>a;
cin>>m>>b;
dp[0][0]=0;
for(int i=1;i<=n;i++) dp[i][0]=dp[i-1][0]+mat[a[i-1]]['#'];
for(int i=1;i<=m;i++) dp[0][i]=dp[0][i-1]+mat['#'][b[i-1]];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
dp[i][j]=max(dp[i-1][j-1]+mat[a[i-1]][b[j-1]],
max(dp[i-1][j]+mat[a[i-1]]['#'],dp[i][j-1]+mat['#'][b[j-1]]));
}
}
cout<<dp[n][m]<<endl;
}
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
HDU 1080 Human Gene Functions--DP--(变形最长公共子)的更多相关文章
- hdu 1080 Human Gene Functions(DP)
题意: 人类基因由A.C.G.T组成. 有一张5*5的基因表.每格有一个值,叫相似度.例:A-C:-3.意思是如果A和C配对, 则它俩的相似度是-3[P.S.:-和-没有相似度,即-和-不能配对] 现 ...
- HDU 1080 Human Gene Functions
最长公共子序列的变形 题目大意:给出两个基因序列,求这两个序列的最大相似度. 题目中的表格给出了两两脱氧核苷酸的相似度. 状态转移方程为: dp[i][j] = max(dp[i-1][j]+Simi ...
- HDU 1080 Human Gene Functions - 最长公共子序列(变形)
传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- 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: ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
- poj 1080 Human Gene Functions (最长公共子序列变形)
题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- poj1080 - Human Gene Functions (dp)
题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...
随机推荐
- iOS开发- Xcode插件(一)-规范凝视生成器VVDocumenter
分享几个经常使用的Xcode插件. 第一个, 规范凝视生成器VVDocumenter. 顾名思义, 它能够非常方便的为你自己主动加入�凝视 使用效果例如以下: 下载链接:https://github. ...
- Android4.2.2由于越来越多的物理按键(frameworks)
当我们改变frameworks之后可能: make: *** [out/target/common/obj/PACKAGING/checkapi-current-timestamp] 错误 38 解决 ...
- Visual Studio Team Services使用教程--邀请团队成员
- Windows Phone 8 MD5
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Wi ...
- Finding awesome developers in programming interviews(转)
英文原文:Finding awesome developers in programming interviews 我曾在一次面试中要求一个很有经验的嵌入式软件开发人员写出一个反转一段字符串并输出到屏 ...
- tomcatserver解析(六)-- Acceptor
Acceptor负责用来管理连接到tomcatserver的数量,来看看Acceptor在tomcatserver中的应用,是怎样实现连接管理的,socket连接建立成功之后,是怎样实现内容的读写的( ...
- Javascript入门视频教程
1,第一节 http://pan.baidu.com/play/video#video/path=%2F%E6%95%99%E5%AD%A61.mov&t=-1 2,第二节 http://pa ...
- vim cheat sheet
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzE1Mjg5NQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Winpcap网络编程十之Winpcap实战,两台主机通过中间主机通信
注:源码等等的我不会全然公开的,此篇文章写出来为大家的网络编程或者课程设计提供一定的思路.. 好,本次我们须要完毕的任务是: 完毕两台主机通过中间主机的数据通信(网络层) 添加基于IP地址的转发功能 ...
- Git是个好工具(转)
Git是分布式版本控制系统,我们常用的版本控制工具还有SVN.这里就得区分下什么是分布式版本控制系统,什么是集中化的版本控制系统. 集中化的版本控制系统 集中化的版本控制系统( Centralized ...