DP。wa了一下午,原来是把mmax写在外层循环了。最近事情太多了,刷题根本没状态。

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <iostream>
using namespace std; #define MAXN 205
#define INF -99999
#define TOKEN '-' char r[MAXN], l[MAXN];
int dp[MAXN][MAXN];
int t, n, rn, ln;
map<char, int> m; int mmap[][] = {
{, -, -, -, -},
{-, , -, -, -},
{-, -, , -, -},
{-, -, -, , -},
{-, -, -, -, }
}; int getmax(int a, int b) {
return a>b ? a:b;
} void init() {
m['A'] = ;
m['C'] = ;
m['G'] = ;
m['T'] = ;
m[TOKEN] = ;
} int main() {
int i, j, k, tmp, mmax;
init(); #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%d", &t);
while (t--) {
scanf("%d %s", &rn, r);
scanf("%d %s", &ln, l);
dp[rn][ln] = ;
for (i=rn-; i>=; --i) {
dp[i][ln] = dp[i+][ln] + mmap[m[r[i]]][];
}
for (j=ln-; j>=; --j) {
dp[rn][j] = dp[rn][j+] + mmap[][m[l[j]]];
}
for (i=rn-; i>=; --i) {
for (j=ln-; j>=; --j) {
mmax = INF;
if (r[i] == l[j])
mmax = getmax(mmax, mmap[m[r[i]]][m[l[j]]]+dp[i+][j+]);
else {
mmax = getmax(mmax, mmap[m[r[i]]][]+dp[i+][j]);
mmax = getmax(mmax, mmap[m[l[j]]][]+dp[i][j+]);
mmax = getmax(mmax, mmap[m[r[i]]][m[l[j]]]+dp[i+][j+]);
}
dp[i][j] = mmax;
}
}
printf("%d\n", dp[][]);
} return ;
}

【HDOJ】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 【dp】

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

  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. poj 1080 Human Gene Functions(dp)

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

  6. hdu 1080 Human Gene Functions(DP)

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

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

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

随机推荐

  1. 关于Hibernate脏检查与快照

    脏检查 Session到底是如何进行脏检查的呢?当一个Customer对象被加入到Session缓存中时,Session会 为Customer对象的值类型的属性复制一份快照.当Session清理缓存时 ...

  2. 1033 - Merging Maps

    Pictures taken from an airplane or satellite of an ar ea to be mapped are often of sufficiently high ...

  3. swift开发笔记24 解决键盘遮挡输入框 的方法

    很简单,就是开始输入时把整个view的frame上移,也就是把y值减小就行了,至于减少多少自己调 ,也可以动态获取参见(http://blog.csdn.net/lengshengren/articl ...

  4. IIS rewrite映射规则语法格式

    IIS rewrite映射规则语法格式,特殊符号:&请用& amp;代替,否则异常. <configuration> <system.webServer> &l ...

  5. 零基础学习云计算及大数据DBA集群架构师【Linux Bash Shell编程及系统自动化2015年1月21日周四】

    lvy老师教项目课程,以及代课了shell部分课程,大家都觉得这位老师不行,上课时做的操作很多都是错误的,觉得她基础不好.而且,她不能解释原因,学生问为什么,她不知道.崩溃啊.向xx培训机构反应后,说 ...

  6. HDU 5144 NPY and shot(三分法)

    当时做这道题时一直想退出物理公式来,但是后来推到导数那一部分,由于数学不好,没有推出来那个关于Θ的最值,后来直接暴力了,很明显超时了,忘了三分法的应用,这道题又是典型的三分求最值,是个单峰曲线,下面是 ...

  7. 【Asp.Net】后台生成控件并绑定事件

    在Asp.Net的Web页面处理流程中,有时候我们会碰到需要动态生成的控件,并为之绑定相应的事件. 接下来我们来动态的生成一个控件 //在用户代码初始化阶段添加控件 protected void Pa ...

  8. jquery.ajax提交多值(数组)

    偶尔会遇到类似复选框的一个属性存在多值情况,若使用ajax提交的化,设置data :{ids:[1,2,3,4]} 提交后,后台无法使用ids获取到数据. 这里可以用到ajax的 traditiona ...

  9. PHP 单链表

    <?php class Hero { public $no; public $name; public $nickname; public $next=null; public function ...

  10. spring源码分析构建

    命令如下: ant ant install-maven ant jar package E:\download\spring-framework-3.1.3.RELEASE\build-spring- ...