poj 1080 Human Gene Functions (最长公共子序列变形)
题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长;其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值。
题解:这题运用dp的解法是借用了求最长公共子序列的方法,,定义dp[i][j]代表s1以第i位结尾的串和s2以第j位结尾的串匹配时所能得到的最大匹配值;那么状态转移方程为:dp[i][j]=max( dp[i-1][j-1]+s1[i]和s2[j]的匹配值 , dp[i-1][j]+s1[i]和'-'的匹配值 , dp[i][j-1]+s2[j]和'-'的匹配值 ); 另外要初始化dp[0][0]=0以及dp[i][0]和dp[0][j]的值。
AC代码:
/**
*@author Wixson
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <stack>
const int inf=0x3f3f3f3f;
const double PI=acos(-1.0);
const double EPS=1e-;
using namespace std;
typedef long long ll;
typedef pair<int,int> P; char s1[],s2[];
int len1,len2;
int dp[][];
int m[][] = {{,-,-,-,-},
{-,,-,-,-},
{-,-,,-,-},
{-,-,-,,-},
{-,-,-,-,}};
int d[];
int max(int a,int b,int c)
{
return max(a,max(b,c));
}
int main()
{
//freopen("input.txt","r",stdin);
d['A']=,d['C']=,d['G']=,d['T']=,d['-']=;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%s",&len1,s1+);
scanf("%d%s",&len2,s2+);
//
dp[][]=;
for(int i=;i<=len1;i++) dp[i][]=dp[i-][]+m[d[s1[i]]][d['-']];
for(int i=;i<=len2;i++) dp[][i]=dp[][i-]+m[d['-']][d[s2[i]]];
//
for(int i=;i<=len1;i++)
{
for(int j=;j<=len2;j++)
{
dp[i][j]=max(dp[i-][j-]+m[d[s1[i]]][d[s2[j]]],dp[i-][j]+m[d[s1[i]]][d['-']],dp[i][j-]+m[d['-']][d[s2[j]]]);
}
}
//
printf("%d\n",dp[len1][len2]);
}
return ;
}
poj 1080 Human Gene Functions (最长公共子序列变形)的更多相关文章
- HDU 1080 Human Gene Functions - 最长公共子序列(变形)
传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...
- 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 ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- POJ 1080 Human Gene Functions
题意:给两个DNA序列,在这两个DNA序列中插入若干个'-',使两段序列长度相等,对应位置的两个符号的得分规则给出,求最高得分. 解法:dp.dp[i][j]表示第一个字符串s1的前i个字符和第二个字 ...
- POJ 1080 Human Gene Functions 【dp】
题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...
- P 1080 Human Gene Functions
大概作了一周,终于A了 类似于求最长公共子序列,稍有变形 当前序列 ch1 中字符为 a,序列 ch2 中字符为 b 则有 3 种配对方式: 1. a 与 b 2. a 与 - 3. - 与 b 动态 ...
随机推荐
- 【BZOJ1939】[Croatian2010] Zuma(动态规划)
题目: BZOJ1939(权限题) 分析: 这题很容易看出是DP,但是状态和转移都不是很好想-- 用\(dp[l][r][c]\)表示在\(l\)前面已经新加了\(c\)个和\(l\)一样的弹子时,使 ...
- Mac上随时切换PYTHON版本
在MAC上,默认安装了python2.*,自己又安装了python3.*:假如我们需要在终端上随时切换python控制台到需要的版本,可以采用下面的方法. 1.用命令 sudo vi ~/.bas ...
- oracle 行转列函数pivot和unpivot
今天接到业务部门的一个需求,需要对同一公司的不同财务指标进行排序,需要用到oracle的行转列函数unpivot. 财务报表的表结构为: 要实现业务部门的排序筛选功能,需要首先将行数据转为列数据: 使 ...
- Laravel (5.5.33) 加载过程---make方法(四)
/** * Resolve the given type from the container. * * @param string $abstract * @return mixed */ publ ...
- 重绘DataGridView标头
最近突然想在DataGridView标头放置一个CheckBox,我就想着重写下DataGridViewColumnHeaderCell抱着试试的心态结果真的是可以的下面是源码:(如果有看不懂的可以加 ...
- Java 基础入门随笔(1) JavaSE版——java语言三种技术架构
1.java语言的三种技术架构: J2SE(java 2 Platform Standard Edition):标准版,是为开发普通桌面和商务应用程序提供的解决方案.该技术体系是其他两者的基础,可以完 ...
- dos命令在vba中应用
正常情况下想要遍历文件夹和子文件夹,可以采用递归的方式 Sub ListFilesTest() With Application.FileDialog(msoFileDialogFolderPicke ...
- php银联支付
简介 PHP银联支付 流程 1.注册 银联 - 技术开发平台和商户服务平台 https://open.unionpay.com 注意:注册时建议使用IE浏览器,之前注册时插件老是用不了,使用IE10以 ...
- cv的期刊和会议
http://blog.csdn.net/tmylzq187/article/details/51111421
- 求n!(高精度问题)
#include <iostream> #include <stdio.h> #define MAX 10000 using namespace std; void Mul(i ...