【HDOJ】1080 Human Gene Functions
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的更多相关文章
- poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- POJ 1080 Human Gene Functions 【dp】
题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- hdu 1080 Human Gene Functions(DP)
题意: 人类基因由A.C.G.T组成. 有一张5*5的基因表.每格有一个值,叫相似度.例:A-C:-3.意思是如果A和C配对, 则它俩的相似度是-3[P.S.:-和-没有相似度,即-和-不能配对] 现 ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
- P 1080 Human Gene Functions
大概作了一周,终于A了 类似于求最长公共子序列,稍有变形 当前序列 ch1 中字符为 a,序列 ch2 中字符为 b 则有 3 种配对方式: 1. a 与 b 2. a 与 - 3. - 与 b 动态 ...
- HDU 1080 Human Gene Functions
最长公共子序列的变形 题目大意:给出两个基因序列,求这两个序列的最大相似度. 题目中的表格给出了两两脱氧核苷酸的相似度. 状态转移方程为: dp[i][j] = max(dp[i-1][j]+Simi ...
随机推荐
- MySQL慢查询(二) - pt-query-digest详解慢查询日志
一.简介 pt-query-digest是用于分析mysql慢查询的一个工具,它可以分析binlog.General log.slowlog,也可以通过SHOWPROCESSLIST或者通过tcpdu ...
- wxPython学习笔记(三)
要理解事件,我们需要知道哪些术语? 事件(event):在你的应用程序期间发生的事情,它要求有一个响应. 事件对象(event object):在wxPython中,它具体代表一个事件,其中包括了事件 ...
- ffmpeg错误隐藏框架分析
本文主要是分析ffmpeg的错误隐藏框架,故解码流程此处不会特地进行讨论,网上其他地方其实也有不少介绍相关流程的了,但发现基本没有介绍错误隐藏流程的,故本文希望能填补这个空白. 我们直接从decode ...
- Core Services 层
Core Services层为所有的应用程序提供基础系统服务.可能应用程序并不直接使用这些服务,但它们是系统很多部分赖以建构的基础. 高阶特性 下面的部分描述一些比较常见特性,也许您正打算让您的应用程 ...
- poj 3046 Ant Counting (DP多重背包变形)
题目:http://poj.org/problem?id=3046 思路: dp [i] [j] :=前i种 构成个数为j的方法数. #include <cstdio> #include ...
- codevs 4650 破损的键盘(链表)
/* 之前一直不重视链表 (好吧说实话主要是看着板子都是指针就怂了T.T) 这道题比较基础 应用了链表的思想 数组模拟指针 遇到的问题就是跑着跑着光标跳到前面或者跳到后面 我们用next储存每个点下一 ...
- java图片缩放
package com.rubekid.springmvc.utils; import java.awt.AlphaComposite; import java.awt.Graphics2D; imp ...
- apache的500错误是写到哪个文件里面
apache的500错误是写到哪个文件里面
- (转)jquery.validate.js 的 remote 后台验证
之前已经有一篇关于jquery.validate.js验证的文章,还不太理解的可以先看看:jQuery Validate 表单验证(这篇文章只是介绍了一下如何实现前台验证,并没有涉及后台验证remot ...
- The account '' has no team with ID ''
Xcode 升级到7.2 版本,真机测试的时候报错:The account '' has no team with ID '' 解决办法1:http://stackoverflow.com/quest ...