大概作了一周,终于A了

类似于求最长公共子序列,稍有变形

当前序列 ch1 中字符为 a,序列 ch2 中字符为 b

则有 3 种配对方式:

1. a 与 b

2. a 与 -

3. - 与 b

动态转移方程:

dp[i][j] = max(dp[i - 1][j - 1] + g(ch1[i],ch2[j]) , dp[i - 1][j] + g(ch1[i],‘-') , dp[i][j-1] + g('-',ch2[j]))

代码如下:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[][];
int g(char a,char b)
{
if( a == b ) return ;
if(a == 'A' && b == 'C' || b == 'A' && a == 'C') return -;
if(a == 'A' && b == 'G' || b == 'A' && a == 'G') return -;
if(a == 'A' && b == 'T' || b == 'A' && a == 'T') return -;
if(a == 'C' && b == 'G' || b == 'C' && a == 'G') return -;
if(a == 'C' && b == 'T' || b == 'C' && a == 'T') return -;
if(a == 'G' && b == 'T' || b == 'G' && a == 'T') return -;
if(a == 'A' && b == '-' || b == 'A' && a == '-') return -;
if(a == 'C' && b == '-' || b == 'C' && a == '-') return -;
if(a == 'G' && b == '-' || b == 'G' && a == '-') return -;
if(a == 'T' && b == '-' || b == 'T' && a == '-') return -;
}
int main()
{
char ch1[],ch2[];
int t,s1,s2;
scanf("%d",&t);
while(t--)
{
memset(dp,,sizeof(dp));
scanf("%d %s",&s1,ch1 + );
scanf("%d %s",&s2,ch2 + );
for(int i = ; i <= s1 ; i ++)
dp[i][] = dp[i - ][] + g('-',ch1[i]);
for(int i = ; i <= s2 ; i ++)
dp[][i] = dp[][i - ] + g(ch2[i],'-');
for(int i = ; i <= s1 ; i ++)
for(int j = ; j <=s2 ; j ++)
dp[i][j] = max(dp[i-][j-] + g(ch1[i],ch2[j]),
max(dp[i-][j] + g(ch1[i],'-'),dp[i][j - ] + g('-',ch2[j])));
printf("%d\n",dp[s1][s2]);
}
return ;
}

P 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. HDU 1080 Human Gene Functions

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

  7. POJ 1080 Human Gene Functions

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

  8. 【HDOJ】1080 Human Gene Functions

    DP.wa了一下午,原来是把mmax写在外层循环了.最近事情太多了,刷题根本没状态. #include <cstdio> #include <cstring> #include ...

  9. POJ 1080 Human Gene Functions 【dp】

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

随机推荐

  1. ef 对象无法序列化的问题(System.Data.Entity.DynamicProxies)

    错误提示: System.InvalidOperationException: 生成 XML 文档时出错. ---> System.InvalidOperationException: 不应是类 ...

  2. 在JSP中使用JavaBean

    //创建一个PersonBean类 public class PersonBean {    private String name;    private int age;    public Pe ...

  3. java io流之BufferReader&BufferedWriter

    BufferedReader 由Reader类扩展而来,提供通用的缓冲方式文本读取,而且提供了很实用的readLine,读取一个文本行,从字符输入流中读取文本,缓冲各个字符,从而提供字符.数组和行的高 ...

  4. Oracle:ORA-00955: name is already used by an existing object

    下午从生产库导出了一份表结构,用来测试一些问题,由于生产库连接着其他用户下的表所以通过视图在本地模拟一下,于是创建视图: create or replace view csews as select ...

  5. poj 1384 Piggy-Bank(完全背包)

    Piggy-Bank Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10830   Accepted: 5275 Descr ...

  6. WebService基本概念及原理

    一.Web Service基本概念 WebService是一种跨编程语言和跨操作系统平台的远程调用技术.Web Service也叫XML Web Service WebService是一种可以接收从I ...

  7. 技术英文单词贴--N

    N normally 正常地,一般地

  8. 如何理解反向传播 Backpropagation 梯度下降算法要点

    http://colah.github.io/posts/2015-08-Backprop/ http://www.zhihu.com/question/27239198 待翻译 http://blo ...

  9. 课堂Beta发布140字评论

    Beta发布140字评论: 第一组:飞天小女警 此项目组的功能是礼物挑选,创意十足,用户只要一听名字便会被深深吸引,并且页面设计感,时尚感十足,不断吸引客户的眼球,而且发布到云服务器上面. 第二组:金 ...

  10. jqueryValidation使用

    jq form表单前端校验可以使用jq插件jquery-validation.js.具体的使用方法: 1.引入文件: <link rel="stylesheet" href= ...