最长公共子序列的变形

题目大意:给出两个基因序列,求这两个序列的最大相似度。

题目中的表格给出了两两脱氧核苷酸的相似度。

状态转移方程为:

dp[i][j] = max(dp[i-1][j]+Similarity(s1[i], '-'),
                     dp[i][j-1]+Similarity(s2[j], '-'),
                     dp[i-1][j-1]+Similarity(s1[i], s2[j]));

注意边界的初始化。

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; char s1[], s2[];
int dp[][]; int table[][] = {
, -, -, -, -,
-, , -, -, -,
-, -, , -, -,
-, -, -, , -,
-, -, -, -,
}; int max(int a, int b, int c)
{
return max(max(a, b), c);
} int f(char c)
{
if(c == 'A') return ;
if(c == 'C') return ;
if(c == 'G') return ;
if(c == 'T') return ;
if(c == '-') return ;
} int Similarity(char c1, char c2)
{ return table[f(c1)][f(c2)]; } int main(void)
{
#ifdef LOCAL
freopen("1080in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int len1, len2, i, j;
dp[][] = ;
scanf("%d %s", &len1, s1+);
scanf("%d %s", &len2, s2+);
for(i = ; i <= len1; ++i)
dp[i][] = dp[i-][] + Similarity(s1[i], '-');
for(i = ; i <= len2; ++i)
dp[][i] = dp[][i-] + Similarity(s2[i], '-');
for(i = ; i <= len1; ++i)
for(j = ; j <= len2; ++j)
dp[i][j] = max(dp[i-][j]+Similarity(s1[i], '-'),
dp[i][j-]+Similarity(s2[j], '-'),
dp[i-][j-]+Similarity(s1[i], s2[j])); printf("%d\n", dp[len1][len2]);
}
return ;
}

代码君

HDU 1080 Human Gene Functions的更多相关文章

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

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

  2. hdu 1080 Human Gene Functions(DP)

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

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

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

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

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

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

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

  6. poj 1080 Human Gene Functions(dp)

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

  7. dp poj 1080 Human Gene Functions

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

  8. P 1080 Human Gene Functions

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

  9. POJ 1080 Human Gene Functions

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

随机推荐

  1. 驱动笔记 - Makefile

    ifneq ($(KERNELRELEASE),) obj-m := hello.ohello-objs := main.o add.o else KDIR := /lib/modules/2.6.1 ...

  2. Win7 VMWare 串口通信

    下载安装工具: 1. 如果电脑(笔记本)没有串口接口,则需要使用一个 USB-Serial 转换线,这里使用 prolific usb-serial USB--串口转换线,首先需要在win7上安装对应 ...

  3. 使用Visio进行UML建模

    http://www.qdgw.edu.cn/zhuantiweb/jpkc/2009/rjkf/xmwd/Visio_UmlModel.htm#_Toc80417837 内容提纲: 1.VISIO中 ...

  4. 传说中的WCF(11):会话(Session)

    在标题中我加了一个大家都很熟悉的单词——Session,熟吧?玩过Web开发的朋友肯定在梦中都会见到她. 在Web中为什么要会话呢?毕竟每个用户在一个Web应用中可能不止进行一次操作,比如,某二手飞机 ...

  5. Jmeter正则表达式提取器的使用方法(转)

    下面简单介绍一下Jmeter正则表达式提取器的使用方法. 1.添加Jmeter正则表达式提取器:在具体的Request下添加Jmeter正则表达式提取器(Jmeter正则表达式在“后置处理器”下面)  ...

  6. lintcode:两个数组的交

    题目 返回两个数组的交 样例 nums1 = [1, 2, 2, 1], nums2 = [2, 2], 返回 [2]. 解题 排序后,两指针找相等元素,注意要去除相同的元素 public class ...

  7. vmware通过vmnet8共享本地网络

    转载于:http://zhaolongchn.blog.163.com/blog/static/19065850420122595117886/ 1,首先将真实电脑的虚拟网卡VMnet8启用 2,然后 ...

  8. RxJava+Retrofit+MVP构建的App——聚合资讯

    RtfRxMVP 聚合资讯APP,提供热点资讯,天气预报以及笑话精选服务,使用 Retrofit + RxJava + MVP 构建代码. Hello U 这是我的一个练习项目,第一次尝试运用 MVP ...

  9. css属性

    文本: color 颜色 line-height 行高 direction 文本方向 letter-spacing 字符间距 text-align 对齐方式 text-decoration 文本修饰 ...

  10. wordpress模块无法拖拽/显示选项点击无反应

    问题:wordpress模块无法拖拽/显示选项点击无反应,还有编辑器的全屏什么的都用不了,按F12查看了console,提示很多jQuery is not defined... 解决方法:把wp-in ...