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. Android学习_ContentProvider和Uri

    ContentProvider概述 public abstract class ContentProvider extends Object implements ComponentCallbacks ...

  2. JSP九个隐式对象及作用域

    out:JspWriter实例对象,作用域为page(页面执行期) 向客户端输出内容 request:HttpServletRequest实例对象,作用域为request(用户请求期) 请求信息 re ...

  3. 【移动开发】WIFI热点通信(二)

    相信大家在上一篇中已经了解了Android中WIFI热点通信的相关操作知识(http://smallwoniu.blog.51cto.com/3911954/1536126),今天我们将在上一篇代码基 ...

  4. dp 斯特林数 HDU2512一卡通大冒险

    这道题其实就是斯特林数,找不同的集合,一共有多少中组法,递推式就是dp[n][k] = dp[n - 1][k - 1] + k * dp[n - 1][k]; 这个式子可以这么解释,dp[n][k] ...

  5. Linux LVM 扩展磁盘分区

    系统:centos 6.3--新建分区 fdisk -l /dev/sdc       # 查看分区 fdisk /dev/sdc          # 创建分区 :n                 ...

  6. MVC的Model层中的一些便签

    由于自己重新接触MVC,所以把Model层里的一些标签给记录下来,方便自己的使用. 这些是自己目前试用过的一些,在以后的工作中我会接着补充进去新的内容

  7. OD: DEP & Ret2Libc

    Data Execution Prevention,数据执行保护,专门用来弥补计算机对数据和代码混淆这一天然缺陷. DEP 的原理是将数据所在的内存页(默认的堆.各种堆栈页.内存池页)标记为不可执行, ...

  8. js接收复选框的值

    <td><input type="checkbox" class="title" name="title" value=& ...

  9. 利用eclipse开发php<转>

    1.安装php环境 Eclipse支持PHP自动提示 其实如果你已经安装好了php环境(安装过程见)的话,只需要下面2步就可以了.hoho,很简单的. 1,下载eclipse中php的插件phpecl ...

  10. MD5加密类

    public class MD5Util { public static String getMD5(String s) { char hexDigits[] = {'0', '1', '2', '3 ...