大概作了一周,终于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. java_js_json_日期格式化

    调用方法: var createBeginTime= createBeginTime.Format("yyyy-MM-dd 00:00:00"); 方法: Date.prototy ...

  2. MINA系列学习-IoAccpetor

    其实在mina的源码中,IoService可以总结成五部分service责任.Processor线程处理.handler处理器.接收器和连接器,分别对应着IoService.IoProcessor.I ...

  3. numberOfRowsInSection方法什么时候调用

    昨天在代码里遇到个问题,很简单的数组越界,但是真心觉得自己把数据处理的思路都理清了不应该会出现这种情况,而且打印出来出现了"灵异事件",那就是行数只有14行,但是cell加载到了1 ...

  4. Python:socket

    Socket:又称"套接字",应用程序通常通过"套接字"向网络发出请求或者应答网络请求,使主机间或者一台计算机上的进程间可以通讯. socket()函数 Pyt ...

  5. transform-style: preserve-3d在iphone下的bug

    经测,当元素设置transform-style: preserve-3d;后,其实现rotateY时的动画效果会穿透上层的覆盖图层. 马克一下

  6. hibernate基础

    另存为查看吧

  7. IOS XML解析

    <?xml version = "1.0"  encoding ="utf-8"?> <video>小黄人</video> ...

  8. rem介绍

    手机端开发,一般以320px宽为最低标题.市场上的手机,大多数是360px宽. 20px=1rem是最容易换算的,基本上可以口算,除以2并缩小十倍.1px/20=0.05rem.两位小数就可以除尽了. ...

  9. jquery双击事件

    <html> <head><meta http-equiv="Content-Type" content="text/html; chars ...

  10. 把页面上的图表导出为pdf文件,分享一种请求下载文件的方法

    最近客户提出一个需求,就是把页面上的图表导出为pdf文件. 找了很多资料.终于有了点头绪.最主要是参考了HighCharts的做法.http://www.hcharts.cn/ 实现原理:把页面图表的 ...