动态规划(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 ...
随机推荐
- phantomJs原理
引用文段:链接:https://www.jianshu.com/p/0254391918f7 网页渲染可分为服务端渲染和客户端渲染,前者是指你在浏览器地址栏输入一个网址,Web服务器处理请求过程就将所 ...
- elastic 集群安装
Elastic Search 安装和配置 1.下载 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6. ...
- c++ MFC图像处理CImage类常用操作代码
原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/9598974.html MFC图像处理CImage类常用操作 CImage类头文件为#inclu ...
- Linux服务器性能评估与优化--转
http://www.itlearner.com/article/4553 一.影响Linux服务器性能的因素 1. 操作系统级 Ø CPU Ø 内存 Ø 磁盘I/ ...
- SpringBoot | 第三十三章:Spring web Servcies集成和使用
前言 最近有个单位内网系统需要对接统一门户,进行单点登录和待办事项对接功能.一般上政府系统都会要求做统一登录功能,这个没啥问题,反正业务系统都是做单点登录的,改下shiro相关类就好了.看了接入方案, ...
- libtar 和 libz 的使用
libtar 和 libz 的使用 用c代码生成 tar.gz 文件 实现的功能和 tar -zcf 命令一样 大概流程为 1.先用libtar相关函数对某个目录生成tar文件 2.然后对tar文件 ...
- 【设计模式】template method(模板方法)-- 类行为型模式5.10
1.意图 子类在不改变父类的算法结构的情况下,可以重定义算法的某些特定步骤 2.动机 模板方法用一些抽象的操作定义一个算法,子类重定义这些操作以提供具体的行为:步骤的顺序定了,但实现可以调整: 3.适 ...
- git的commit规范及强制校验
1.背景 在多人协作项目中,如果代码风格统一.代码提交信息的说明准确,那么在后期协作以及Bug处理时会更加方便. 先来介绍本人公司采用的commit规范 Commit message格式 < ...
- Stage1--Python的特点和安装
说在前面: Stage1-Stage4简单介绍一下Python语法,Stage5开始用python实现一些实际应用,语法的东西到处可以查看到,学习一门程序语言的最终目的是应用,而不是学习语法,语法本事 ...
- java面试题----工厂模式大整理(面试问的较多)
在一次面试中了解到工厂模式在实际应用中的重要性,可以说工厂模式的应用随处可见,以下是百度百科对工厂模式的介绍 工厂模式是我们最常用的实例化对象模式了,是用工厂方法代替new操作的一种模式.著名的Jiv ...