POJ 1080 Human Gene Functions
题意:给两个DNA序列,在这两个DNA序列中插入若干个'-',使两段序列长度相等,对应位置的两个符号的得分规则给出,求最高得分。
解法:dp。dp[i][j]表示第一个字符串s1的前i个字符和第二个字符串s2的前j个字符对齐时的最高得分,转移方程:dp[i][j] = max{dp[i - 1][j - 1] + a[s1[i]][s2[j]], dp[i - 1] + a[s1[i]]['-'] + dp[i][j - 1] + a['-'][s2[j]]},第一项表示对齐时s1[i]和s2[j]作为结尾,第二项表示对齐时'-'和s2[j]作为结尾,第三项表示对齐时s1[i]和'-'作为结尾。
注意dp应该以1开始,但字符串一般直接读入的话是以0开始的,因为这个样例一直过不去……调了好久……
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
int a[5][5] = {5, -1, -2, -1, -3,
-1, 5, -3, -2, -4,
-2, -3, 5, -2, -2,
-1, -2, -2, 5, -1,
-3, -4, -2, -1, 0};
int main()
{
int T;
while(~scanf("%d", &T))
{
while(T--)
{
string s1, s2;
int len1, len2;
cin >> len1 >> s1 >> len2 >> s2;
for(int i = 0; i < len1; i++)
if(s1[i] == 'A') s1[i] = 0;
else if(s1[i] == 'C') s1[i] = 1;
else if(s1[i] == 'G') s1[i] = 2;
else if(s1[i] == 'T')s1[i] = 3;
for(int i = 0; i < len2; i++)
if(s2[i] == 'A') s2[i] = 0;
else if(s2[i] == 'C') s2[i] = 1;
else if(s2[i] == 'G') s2[i] = 2;
else if(s2[i] == 'T') s2[i] = 3;
int dp[105][105] = {0};
for(int i = 1; i <= len1; i++)
dp[i][0] = dp[i - 1][0] + a[s1[i - 1]][4];
for(int i = 1; i <= len2; i++)
dp[0][i] = dp[0][i - 1] + a[4][s2[i - 1]];
for(int i = 1; i <= len1; i++)
for(int j = 1; j <= len2; j++)
dp[i][j] = max(dp[i - 1][j - 1] + a[s1[i - 1]][s2[j - 1]], max(dp[i - 1][j] + a[s1[i - 1]][4], dp[i][j - 1] + a[4][s2[j - 1]]));
printf("%d\n", dp[len1][len2]);
}
}
return 0;
}
POJ 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 -- 动态规划(最长公共子序列)
题目地址: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 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
- POJ 1080 Human Gene Functions 【dp】
题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...
- poj 1080 Human Gene Functions (最长公共子序列变形)
题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...
- 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 ...
随机推荐
- C# 静态类
静态类是不能实例化的,我们直接使用它的属性与方法,静态类最大的特点就是共享. 探究 public static class StaticTestClass { ; public static void ...
- POJ 2080 Calendar(很水的模拟)
刚开始一直WA,才发现原来代码中两处减去年份.月份的天数的判断条件用的是>=,虽然最后考虑n=0要退回一天的情况,但还是WA.后来改成>的条件判断,省去了考虑n=0的麻烦,AC. 此题无非 ...
- android 输入法的打开和关闭
一.打开输入法窗口: InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.IN ...
- 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Session过期,跳出iframe等框架
//在你想控制跳转的页面,如login.jsp中的<head>与</head>之间加入以下代码: if(window != top){ //解决Sessio ...
- java基础面试题(转)
JAVA相关基础知识1.面向对象的特征有哪些方面 1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时 ...
- MIT算法导论——第四讲.Quicksort
本栏目(Algorithms)下MIT算法导论专题是个人对网易公开课MIT算法导论的学习心得与笔记.所有内容均来自MIT公开课Introduction to Algorithms中Charles E. ...
- NOT EXISTS优化的一个案例 .
原始语句: SELECT * FROM dcf_account.t_posting_transaction t1 WHERE NOT EXISTS ( SELECT * FROM dcf_loan.t ...
- Buffer数据结构和new IO的Memory-mapped files
一.Buffer类 java.nio.Buffer这个类是用来干什么的?有怎样的结构? "Core Java"中是这样定义的“A buffer is array of values ...
- Learning Lua Programming (2) Lua编程基础
开始学习Lua编程,首先从一些简单的语法开始. 一.编辑环境 下面推荐一个Lua编程的IDE,感觉是很强大的.ZeroBrane Studio,windows平台,mac平台都有.点击打开链接 官方 ...