动态规划(DP),Human Gene Functions
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1027
http://poj.org/problem?id=1080
解题报告:
1、类似于LCS
2、gene[i][j]表示str1[i-1]和str2[j-1]的分值串没有,则应该扣分
3、递推公式
temp1=gene[i-1][j-1]+score[_map[str1[i-1]]][_map[str2[j-1]]];
temp2=gene[i-1][j]+score[_map[str1[i-1]]][4];
temp3=gene[i][j-1]+score[4][_map[str2[j-1]]];
gene[i][j]=max(temp1,max(temp2,temp3));
4、在初始化边界条件时,认为一个字符串为空,则要扣分
#include <cstdio>
#include <algorithm>
#include <map>
#define NUM 105 using namespace std; int score[][]= {{,-,-,-,-},{-,,-,-,-},{-,-,,-,-},{-,-,-,,-},{-,-,-,-,}}; map<char,int> _map; char str1[NUM],str2[NUM];
int len1,len2; int gene[NUM][NUM];///gene[i][j]表示基因子串str1[i-1]和str2[j-1]的分值. int main()
{
_map['A']=,_map['C']=,_map['G']=,_map['T']=,_map['-']=;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%s",&len1,str1);
scanf("%d%s",&len2,str2);
///初始化边界条件
gene[][]=;
for(int i=; i<=len1; i++)
gene[i][]=gene[i-][]+score[_map[str1[i-]]][];
for(int i=; i<=len2; i++)
gene[][i]=gene[][i-]+score[][_map[str2[i-]]];
int m1,m2,m3;
for(int i=; i<=len1; i++)
{
for(int j=; j<=len2; j++)
{
m1=gene[i-][j]+score[_map[str1[i-]]][];///str1取i-1个字符,str2取'-';
m2=gene[i][j-]+score[][_map[str2[j-]]];///str1取'-',str2取j-1个字符;
m3=gene[i-][j-]+score[_map[str1[i-]]][_map[str2[j-]]];///str1取i-1个字符,str2取j-1个字符
gene[i][j]=max(m1,max(m2,m3));
}
}
printf("%d\n",gene[len1][len2]);
}
return ;
}
动态规划(DP),Human Gene Functions的更多相关文章
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- Human Gene Functions
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...
- hdu1080 Human Gene Functions() 2016-05-24 14:43 65人阅读 评论(0) 收藏
Human Gene Functions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- 【POJ 1080】 Human Gene Functions
[POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- poj1080 - Human Gene Functions (dp)
题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...
- 杭电20题 Human Gene Functions
Problem Description It is well known that a human gene can be considered as a sequence, consisting o ...
- 刷题总结——Human Gene Functions(hdu1080)
题目: Problem Description It is well known that a human gene can be considered as a sequence, consisti ...
随机推荐
- oracle 单实例DG(切换篇三)
一,开篇 此篇操作承接上文,必须完成DG实例搭建完成方可有执行以下内容的实例 二,切换物理备库 one. oracle01库命令 select switchover_status from v$dat ...
- drupal 7 安装失败后的补救办法
在安装 drupal 7 时安装,导入数据库已经成功,但是在安装语言包的时候卡住了,没有进行最后三步,管理员帐号没能启用.此时我退出安装,访问网站,没有问题.但是管理员admin的密码没有设置,以至于 ...
- cloudemanager安装时出现failed to receive heartbeat from agent问题解决方法(图文详解)
不多说,直接上干货! 安装cdh5到最后报如下错误: 安装失败,无法接受agent发出的检测信号. 确保主机名称正确 确保端口7182可在cloudera manager server上访问(检查防火 ...
- maven pom.xml指定jdk
<plugins> <!-- 指定jdk --> <plugin> <groupId>org.apache.maven.plugins</grou ...
- CF 303C——Minimum Modular——————【剪枝】
Minimum Modular time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- JS异步执行之setTimeout 0的妙用
最近在工作中遇到一些问题,大致是关于js执行问题的.由于没搞清执行顺序,导致出现了一些奇怪的bug. 所以这里整理一些有关异步执行的知识(冰山一角角)... 大家都知道js是单线程的,执行起来是顺序的 ...
- 【转】常用的邮箱服务器(SMTP、POP3)地址、端口
gmail(google.com)POP3服务器地址:pop.gmail.com(SSL启用 端口:995)SMTP服务器地址:smtp.gmail.com(SSL启用 端口:587) 21cn.co ...
- 浅谈C#中HttpWebRequest与HttpWebResponse的使用方法
1.第一招,根据URL地址获取网页信息get方法 public static string GetUrltoHtml(string Url,string type) { try { System.Ne ...
- html+css动态篇
transition过渡 transform旋转 animation动画 一般是父div包含两个子div,一个写鼠标悬浮之前,一个写鼠标悬浮之后, 鼠标悬浮之后的div要写overflow:hidde ...
- 10th week task -1
1:For each ... inFor...in ExamplesFor...of 对以上的内容进行 Examples和Explanation (1)For...in 以任意顺序遍历一个对象的可枚举 ...