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

题解:这题运用dp的解法是借用了求最长公共子序列的方法,,定义dp[i][j]代表s1以第i位结尾的串和s2以第j位结尾的串匹配时所能得到的最大匹配值;那么状态转移方程为:dp[i][j]=max( dp[i-1][j-1]+s1[i]和s2[j]的匹配值 , dp[i-1][j]+s1[i]和'-'的匹配值 , dp[i][j-1]+s2[j]和'-'的匹配值 );  另外要初始化dp[0][0]=0以及dp[i][0]和dp[0][j]的值。

AC代码:

 /**
*@author Wixson
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <stack>
const int inf=0x3f3f3f3f;
const double PI=acos(-1.0);
const double EPS=1e-;
using namespace std;
typedef long long ll;
typedef pair<int,int> P; char s1[],s2[];
int len1,len2;
int dp[][];
int m[][] = {{,-,-,-,-},
{-,,-,-,-},
{-,-,,-,-},
{-,-,-,,-},
{-,-,-,-,}};
int d[];
int max(int a,int b,int c)
{
return max(a,max(b,c));
}
int main()
{
//freopen("input.txt","r",stdin);
d['A']=,d['C']=,d['G']=,d['T']=,d['-']=;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%s",&len1,s1+);
scanf("%d%s",&len2,s2+);
//
dp[][]=;
for(int i=;i<=len1;i++) dp[i][]=dp[i-][]+m[d[s1[i]]][d['-']];
for(int i=;i<=len2;i++) dp[][i]=dp[][i-]+m[d['-']][d[s2[i]]];
//
for(int i=;i<=len1;i++)
{
for(int j=;j<=len2;j++)
{
dp[i][j]=max(dp[i-][j-]+m[d[s1[i]]][d[s2[j]]],dp[i-][j]+m[d[s1[i]]][d['-']],dp[i][j-]+m[d['-']][d[s2[j]]]);
}
}
//
printf("%d\n",dp[len1][len2]);
}
return ;
}

poj 1080 Human Gene Functions (最长公共子序列变形)的更多相关文章

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

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

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

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

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

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

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

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

  5. dp poj 1080 Human Gene Functions

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

  6. poj 1080 Human Gene Functions(dp)

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

  7. POJ 1080 Human Gene Functions

    题意:给两个DNA序列,在这两个DNA序列中插入若干个'-',使两段序列长度相等,对应位置的两个符号的得分规则给出,求最高得分. 解法:dp.dp[i][j]表示第一个字符串s1的前i个字符和第二个字 ...

  8. POJ 1080 Human Gene Functions 【dp】

    题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...

  9. P 1080 Human Gene Functions

    大概作了一周,终于A了 类似于求最长公共子序列,稍有变形 当前序列 ch1 中字符为 a,序列 ch2 中字符为 b 则有 3 种配对方式: 1. a 与 b 2. a 与 - 3. - 与 b 动态 ...

随机推荐

  1. ACM_lowbit

    lowbit Time Limit: 2000/1000ms (Java/Others) Problem Description: long long ans = 0; for(int i = 1; ...

  2. Leetcode03---Longest Substring Without Repeating Characters

    Description: Given a string, find the length of the longest substring without repeating characters. ...

  3. Spring Boot (23) Lettuce Redis

    Spring Boot除了支持常见的ORM框架外,更是对常用的中间件提供了非常好的封装,随着SpringBoot2.x的到来,支持的组件也越来越丰富,也越来越成熟,其中对Redis的支持不仅仅是它丰富 ...

  4. jQuery五屏轮播手风琴切换代码

    jQuery五屏轮播手风琴切换代码 在线演示本地下载

  5. SAS学习笔记之《SAS编程与数据挖掘商业案例》(3)变量操作、观测值操作、SAS数据集管理

    SAS学习笔记之<SAS编程与数据挖掘商业案例>(3)变量操作.观测值操作.SAS数据集管理 1. SAS变量操作的常用语句 ASSIGNMENT 创建或修改变量 SUM 累加变量或表达式 ...

  6. Product Device Lot

    Product是指产品: 这个Product可以在不同的设备类型上生产, 同一类型的设备也可能硬件有差异,所以会有相对应的Device(Recipe): 同一Product(或同一Device)由于数 ...

  7. enc28j60网卡驱动模块添加进linux内核,Kconfig,Makefile配置过程

    这里是要把http://www.cnblogs.com/hackfun/p/6260396.html中的enc28j60网卡驱动模块,添加到2.6.22.6内核中,这个模块代码不需要任何修改.只需要在 ...

  8. 将MongoDB服务器设置成Windows启动服务(win10)

    如题,这个问题也百度了很久,百度还是挺给力的,但是都没能解决问题,后来在大神(原谅我不知道大神叫什么)的指导下,终于设置成功,特分享下设置过程.. MongoDB设置数据库我就不说了...额..算了, ...

  9. 查看Windows XP是否已激活的方法

    打开开始→运行, 在输入:oobe/msoobe /a,回车后系统会弹出窗口告诉你系统是否已经激活

  10. logstash windows下添加服务启动管理

    nssm下载链接:http://nssm.cc/release/nssm-2.24.zip