P 1080 Human Gene Functions
大概作了一周,终于A了
类似于求最长公共子序列,稍有变形
当前序列 ch1 中字符为 a,序列 ch2 中字符为 b
则有 3 种配对方式:
1. a 与 b
2. a 与 -
3. - 与 b
动态转移方程:
dp[i][j] = max(dp[i - 1][j - 1] + g(ch1[i],ch2[j]) , dp[i - 1][j] + g(ch1[i],‘-') , dp[i][j-1] + g('-',ch2[j]))
代码如下:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[][];
int g(char a,char b)
{
if( a == b ) return ;
if(a == 'A' && b == 'C' || b == 'A' && a == 'C') return -;
if(a == 'A' && b == 'G' || b == 'A' && a == 'G') return -;
if(a == 'A' && b == 'T' || b == 'A' && a == 'T') return -;
if(a == 'C' && b == 'G' || b == 'C' && a == 'G') return -;
if(a == 'C' && b == 'T' || b == 'C' && a == 'T') return -;
if(a == 'G' && b == 'T' || b == 'G' && a == 'T') return -;
if(a == 'A' && b == '-' || b == 'A' && a == '-') return -;
if(a == 'C' && b == '-' || b == 'C' && a == '-') return -;
if(a == 'G' && b == '-' || b == 'G' && a == '-') return -;
if(a == 'T' && b == '-' || b == 'T' && a == '-') return -;
}
int main()
{
char ch1[],ch2[];
int t,s1,s2;
scanf("%d",&t);
while(t--)
{
memset(dp,,sizeof(dp));
scanf("%d %s",&s1,ch1 + );
scanf("%d %s",&s2,ch2 + );
for(int i = ; i <= s1 ; i ++)
dp[i][] = dp[i - ][] + g('-',ch1[i]);
for(int i = ; i <= s2 ; i ++)
dp[][i] = dp[][i - ] + g(ch2[i],'-');
for(int i = ; i <= s1 ; i ++)
for(int j = ; j <=s2 ; j ++)
dp[i][j] = max(dp[i-][j-] + g(ch1[i],ch2[j]),
max(dp[i-][j] + g(ch1[i],'-'),dp[i][j - ] + g('-',ch2[j])));
printf("%d\n",dp[s1][s2]);
}
return ;
}
P 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四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
- HDU 1080 Human Gene Functions
最长公共子序列的变形 题目大意:给出两个基因序列,求这两个序列的最大相似度. 题目中的表格给出了两两脱氧核苷酸的相似度. 状态转移方程为: dp[i][j] = max(dp[i-1][j]+Simi ...
- POJ 1080 Human Gene Functions
题意:给两个DNA序列,在这两个DNA序列中插入若干个'-',使两段序列长度相等,对应位置的两个符号的得分规则给出,求最高得分. 解法:dp.dp[i][j]表示第一个字符串s1的前i个字符和第二个字 ...
- 【HDOJ】1080 Human Gene Functions
DP.wa了一下午,原来是把mmax写在外层循环了.最近事情太多了,刷题根本没状态. #include <cstdio> #include <cstring> #include ...
- POJ 1080 Human Gene Functions 【dp】
题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...
随机推荐
- Android——数据的存储和访问
1.数据文件的存取操作 我们可以将数据存取在Android应用数据的默认存储地址,其地址为:安装包/data/data/<package name>/files/ 1)向文件中写入数据 p ...
- c++的默认构造函数 VS 深拷贝(值拷贝) 与 浅拷贝(位拷贝)
C++默认为类生成了四个缺省函数: A(void); // 缺省的无参数构造函数 A(const A &a); // 缺省的拷贝构造函数 ~A(void); // 缺省的析构函数 A & ...
- PTA Hashing
The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...
- UML(统一建模语言)
需求分析阶段 用例图 定义:用例图并不是用来描述用例的.用例图的主要作用是:直观地描述系统对外提供的功能. 用例图的三个要素:角色.系统.用例 用例图的关系: 角色和用例的关系:有关和无关 用例和用例 ...
- 修复 Firefox 下本地使用 Bootstrap 3 时 glyphicon 不显示问题
本地开发使用 Firefox 调试,遇到了 glyphicon 图标不显示的问题,期初以为是路径问题,搜索一大圈后找到了答案,原来这是一个安全性的问题,于是问题就好办了,解决方案如下: 1. 在Fir ...
- 安装一些包管理的记录 win10
我大php的composer 国内镜像包http://pkg.phpcomposer.com/ 还是全局的爽些: omposer config -g repo.packagist composer ...
- 使用merge同时执行insert和update操作
SQL点滴18—SqlServer中的merge操作,相当地风骚 今天在一个存储过程中看见了merge这个关键字,第一个想法是,这个是配置管理中的概念吗,把相邻两次的更改合并到一起.后来在tech ...
- HTML5.dcloud.io-stream-app
dcloud.io提出的Stream App 本文仅仅是关于dcloud.io提出的SteamApp初探,所有内容请参考其官网. 1. Application promotion by scaning ...
- modesim测试语句
: 'd2; Reg2 <= Reg1; i <= i + 1'b1; join : 'd2; i <= i + 1'b1; join : 'd2; Reg2 <= Reg1; ...
- Android 时间维护服务 TimeService(针对于特殊定制设备)
此方法针对于无法自动获取网络时间的特殊设备,正常 Android 设备直接调用 System.currentTimeMillis(); 方法获取当前时间即可. TimeService 集成于 Serv ...