题意:给两个DNA序列,在这两个DNA序列中插入若干个'-',使两段序列长度相等,对应位置的两个符号的得分规则给出,求最高得分。

解法:dp。dp[i][j]表示第一个字符串s1的前i个字符和第二个字符串s2的前j个字符对齐时的最高得分,转移方程:dp[i][j] = max{dp[i - 1][j - 1] + a[s1[i]][s2[j]], dp[i - 1] + a[s1[i]]['-'] + dp[i][j - 1] + a['-'][s2[j]]},第一项表示对齐时s1[i]和s2[j]作为结尾,第二项表示对齐时'-'和s2[j]作为结尾,第三项表示对齐时s1[i]和'-'作为结尾。

注意dp应该以1开始,但字符串一般直接读入的话是以0开始的,因为这个样例一直过不去……调了好久……

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
int a[5][5] = {5, -1, -2, -1, -3,
-1, 5, -3, -2, -4,
-2, -3, 5, -2, -2,
-1, -2, -2, 5, -1,
-3, -4, -2, -1, 0};
int main()
{
int T;
while(~scanf("%d", &T))
{
while(T--)
{
string s1, s2;
int len1, len2;
cin >> len1 >> s1 >> len2 >> s2;
for(int i = 0; i < len1; i++)
if(s1[i] == 'A') s1[i] = 0;
else if(s1[i] == 'C') s1[i] = 1;
else if(s1[i] == 'G') s1[i] = 2;
else if(s1[i] == 'T')s1[i] = 3;
for(int i = 0; i < len2; i++)
if(s2[i] == 'A') s2[i] = 0;
else if(s2[i] == 'C') s2[i] = 1;
else if(s2[i] == 'G') s2[i] = 2;
else if(s2[i] == 'T') s2[i] = 3;
int dp[105][105] = {0};
for(int i = 1; i <= len1; i++)
dp[i][0] = dp[i - 1][0] + a[s1[i - 1]][4];
for(int i = 1; i <= len2; i++)
dp[0][i] = dp[0][i - 1] + a[4][s2[i - 1]];
for(int i = 1; i <= len1; i++)
for(int j = 1; j <= len2; j++)
dp[i][j] = max(dp[i - 1][j - 1] + a[s1[i - 1]][s2[j - 1]], max(dp[i - 1][j] + a[s1[i - 1]][4], dp[i][j - 1] + a[4][s2[j - 1]]));
printf("%d\n", dp[len1][len2]);
}
}
return 0;
}

  

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

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

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

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

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

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

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

  4. poj 1080 Human Gene Functions(dp)

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

  5. dp poj 1080 Human Gene Functions

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

  6. POJ 1080 Human Gene Functions 【dp】

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

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

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

  8. P 1080 Human Gene Functions

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

  9. HDU 1080 Human Gene Functions

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

随机推荐

  1. 企业运营对 DevOps 的「傲慢与偏见」

    摘要:出于各种原因,并非所有人都信任 DevOps .有些人觉得 DevOps 只不过给开发者改善产品提供了一个途径而已,还有的人觉得 DevOps 是一堆悦耳的空头支票,甚至有人认为 DevOps ...

  2. Even Fibonacci numbers

    --Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting ...

  3. javascript分享到的源码

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  4. floodlight 中两个互相矛盾的地方

    floodlight中,添加防火墙规则,0表示最高优先级,数字越大,优先级越低;但是在StaticFlowPusher中写flow的时候,0表示最低优先级,数字越大,优先级越高,32767为最高. f ...

  5. 为什么重写equals方法还要重写hashcode方法?

    我们都知道Java语言是完全面向对象的,在java中,所有的对象都是继承于Object类.Ojbect类中有两个方法equals.hashCode,这两个方法都是用来比较两个对象是否相等的. 在未重写 ...

  6. TCL语言笔记:TCL中的控制结构命令

    一.引言 控制结构允许程序根据不同的状态.条件和参数来选择不同的处理和执行路径,从而使代码具有更强的灵活性.健壮性和可读性. Tcl 提供了 if.if/else.if/elseif.foreach. ...

  7. 手动安装UniDAC的过程

    每次安装都不一样,而且有时候挺麻烦的,所以记下来.我这次安装过程是这样的: 0. 修改Source\Delphi7\Make.bat,填入正确的IdeDir 1.找到source\delphi7目录, ...

  8. Splunk常用命令

    重启/查看状态/停止splunk [root@localhost splunk]# /opt/splunk/bin/splunk restart / status / stop

  9. Java API —— IO流( FileInputStream & FileOutputStream & BufferedInputStream & BufferedOutputStream )

    1.IO流概述 · IO流用来处理设备之间的数据传输        · 上传文件和下载文件        · Java对数据的操作是通过流的方式 · Java用于操作流的对象都在IO包中   2.IO ...

  10. android Json 使用

    http://www.cnblogs.com/mybkn/archive/2012/05/18/2508306.html http://www.cnblogs.com/haippy/archive/2 ...