意甲冠军:该基因序列的两端相匹配,四种不同的核苷酸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--(变形最长公共子)的更多相关文章

  1. hdu 1080 Human Gene Functions(DP)

    题意: 人类基因由A.C.G.T组成. 有一张5*5的基因表.每格有一个值,叫相似度.例:A-C:-3.意思是如果A和C配对, 则它俩的相似度是-3[P.S.:-和-没有相似度,即-和-不能配对] 现 ...

  2. HDU 1080 Human Gene Functions

    最长公共子序列的变形 题目大意:给出两个基因序列,求这两个序列的最大相似度. 题目中的表格给出了两两脱氧核苷酸的相似度. 状态转移方程为: dp[i][j] = max(dp[i-1][j]+Simi ...

  3. HDU 1080 Human Gene Functions - 最长公共子序列(变形)

    传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...

  4. poj 1080 Human Gene Functions(dp)

    题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...

  5. poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】

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

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

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

  7. dp poj 1080 Human Gene Functions

    题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...

  8. poj 1080 Human Gene Functions (最长公共子序列变形)

    题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...

  9. POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)

    题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...

  10. poj1080 - Human Gene Functions (dp)

    题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...

随机推荐

  1. Encountered a section with no Package: header

    刚才打开ubuntu,我的版本号是11.04.正想打开新立得软件工具包更新软件的时候,出现了例如以下错误: E:Encountered a section with no Package: heade ...

  2. openSUSE 国内镜像摘要

    1. 北交(BJTU): http://mirror.bjtu.edu.cn/opensuse http://mirror.bjtu.edu.cn/packman/suse 2. 华中科大(HUST) ...

  3. 解决IIS7中出现An error occurred on the server when processing the URL错误提示的方法

    在IIS7上配置一个asp程序,出现了一个错如提示: An error occurred on the server when processing the URL. Please contact t ...

  4. Android系统APN配置具体解释

     Android 系统APN配置具体解释 这些天一直在调系统原生的Settings.apk里面APN配置的问题.在设置里面手动添加了APN配置选项.可是在界面上还是看不到.所以跟了下代码.原以为就是简 ...

  5. JMS ActiveMQ研究文档

    1. 背景 当前,CORBA.DCOM.RMI等RPC中间件技术已广泛应用于各个领域.但是面对规模和复杂度都越来越高的分布式系统,这些技术也显示出其局限性:(1)同步通信:客户发出调用后,必须等待服务 ...

  6. Sass 基础和入门

    css本身很有趣,但是随着样式表变大,会越来越复杂,更加难以管理.css预处理器在这里就能帮上忙了.SASS 让你使用在css中不存在的特性,譬如变量.嵌套.mixins(混入),继承和一些其他好的特 ...

  7. 2014ACM上海邀请赛A解释称号

    #include <cstdio> #include <cstring> #include <iostream> using namespace std; cons ...

  8. WebAPI 用ActionFilterAttribute实现token令牌验证与对Action的权限控制

    .NET WebAPI 用ActionFilterAttribute实现token令牌验证与对Action的权限控制 项目背景是一个社区类的APP(求轻吐...),博主主要负责后台业务及接口.以前没玩 ...

  9. Json.NET提供依赖注

    Json.NET提供依赖注 [.NET] 使用Json.NET提供依赖注入功能(Dependence Injection) 前言 在一些小型项目的开发情景里,系统不需要大型DI Framework所提 ...

  10. 一张地图告诉你,只JavaScript不够!

    这将是JavaScript语法,你真的会一JavaScript嘛.看看这个图片!超好用JavaScript一本书的摘录游.熊儿.快去学习! 版权声明:本文博客原创文章.博客,未经同意,不得转载.