【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 ...
随机推荐
- atol字符串转换函数应用实例
原型:long atol(const char *nptr); 相关函数 atoi,atol,strtod,strtol,strtoul 头文件:stdlib.h 功能:将字符串转换成整型数 说明:参 ...
- android学习之4种点击事件的响应方式
如题,下面就一一列出对点击事件响应的4种方式: 第一种:内部类的形式: package com.example.dail; import android.net.Uri; import android ...
- monkeyrunner 详细介绍
MonkeyRunner: monkeyrunner工具提供了一个API,使用此API写出的程序可以在Android代码之外控制Android设备和模拟器.通过monkeyrunner,您可以写出一个 ...
- 《UNIX网络编程》之多客户连接服务端,可重用套接字对
该网络编程之客户端与服务端程序模板支持: 1. 多客户端同时连接服务端,即服务程序可以同时为多个客户端服务: 2. 服务端支持套接字对重用,即即使处于TIME_WAIT状态,仍可支持服务端重启: 3. ...
- HttpWebRequest get/post方法实现
get请求url #region GetHttp请求 /// <summary> /// GetHttp请求 /// </summary> /// <param name ...
- NYOJ-569最大公约数之和
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=569 此题目可以用筛选法的思想来做,但是用到一个欧拉函数 gcd(1,12)=1,gcd( ...
- hdu 1232
以前写的.....拿出来看看.... 并查集模板: #include <iostream> #include <string> using namespace std; int ...
- android系统360浏览器使用append动态添加元素出现黑色错乱背景
去掉样式 backface-visibility:hidden;
- Git简明教程
http://www.jianshu.com/p/16ad0722e4cc http://www.jianshu.com/p/f7ec8310ccd2
- 《Linux内核分析》week1作业-分析一个简单c语言的汇编代码
1.C语言源码 #include <stdio.h> int g(int x){ ; } int f(int x){ return g(x); } int main(){ )+; } 2. ...