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 ...
随机推荐
- java核心技术记录之集合
java库中的具体集合: 集合类型 描述 ArrayList 一种可以动态增长和缩减的索引序列 LinkedList 一种可以在任何位置进行高效地插入和删除操作的有序序列 ArrarDeque 一种用 ...
- 包装类型的比较,如:Integer,Long,Double
Integer, Long, Double等基本类型的包装类型,比较时两种方法:第一种:equals, 第二种: .intValue(), .longValue() , .doubleValue ...
- IDEA使用的点点滴滴
查找一个类可以使用快捷键Ctrl + N 那么怎么看这个类中有哪些属性,哪些方法,就像Eclipse中的outline功能呢? 如查看NIO中的Buffer类,Ctrl + N-->
- Java API —— 反射
1.类加载器 1)类的加载 · 当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载,连接,初始化三步来实现对这个类进行初始化. · 加载 :就是 ...
- Use Eclipse to develop groovy[docs.codehaus.org]
http://docs.codehaus.org/display/GROOVY/Install+Groovy-Eclipse+Plugin http://docs.codehaus.org/displ ...
- 关于imx6核心板qt系统U盘挂载
在使用imx6核心板开发的时候,程序写到U盘,想通过U盘在板子上运行程序,U盘插到板子上后在minicom中有信息显示,但是无法找到挂载文件,/dev和/mnt下都没有找到相应的文件.后来百度后发现U ...
- mysql 插入汉字 异常 Incorrect string value: '\xE8\xA7\x84\xE5\x88\x99' for column 'name'
今天使用mysql出现 Incorrect string value: '\xE8\xA7\x84\xE5\x88\x99' for column 'name' 异常 通过查找问题,发现是字段编码不支 ...
- FileObverse文件观察者的Debug报告
FileObverse文件观察者的Debug报告 2014年9月18日 9:03
- Python中的split()函数的使用方法
函数:split() Python中有split()和os.path.split()两个函数,具体作用如下:split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(lis ...
- Android通过JNI调用驱动程序(完全解析实例)
要达到的目的:android系统中,用JAVA写界面程序,调用jni中间库提供的接口,去操作某个驱动节点,实现read,writer ioctl等操作!这对底层驱动开发人员是很重要的一个调试通道,也是 ...