动态规划(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 ...
随机推荐
- Python+Selenium之HTMLTestRunner
下载 HTMLTestRunner 模块 下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html 保存路径:将下载的HTMLTestRunne ...
- Laplace变换要点
Laplace变换在求解微分方程.信号系统.自动控制领域都有重要作用.阅读<复变函数与积分变换>华中科大第三版,小结要点. 方便应用,最先给出变换表: 定义: 性质: 周期函数与卷积:
- bzoj 2741: 【FOTILE模拟赛】L
Description FOTILE得到了一个长为N的序列A,为了拯救地球,他希望知道某些区间内的最大的连续XOR和. 即对于一个询问,你需要求出max(Ai xor Ai+1 xor Ai+2 .. ...
- .net使用redis入门笔记
1.学习blog:http://www.cnblogs.com/yangecnu/p/Introduct-Redis-in-DotNET.html 2.redis官网:http://redis.io/ ...
- Java 访问权限控制- protected 关键字
protected 关键字的真正内涵 文章来源:http://blog.csdn.net/justloveyou_/article/details/61672133 很多介绍Java语言的书籍(包括& ...
- C#学习笔记5
1.接口的显式实现:显式实现需要在实现接口的类型中,在实现接口的成员中添加接口名称的前缀.且没有必要添加public.virtual这些修饰符,因为显式实现只能通过接口调用,不能用实现类进行调用.为此 ...
- python高阶函数sorted
原文 排序也是在程序中经常用到的算法.无论使用冒泡排序还是快速排序,排序的核心是比较两个元素的大小.如果是数字,我们可以直接比较,但如果是字符串或者两个dict呢?直接比较数学上的大小是没有意义的,因 ...
- 前端使用express+node实现接口模拟及websocket通讯
简述如何使用node+express实现接口连接及入门websocket通讯.使用技术栈:node + express + typescript + websocket. 1.接口实现 这里描述前端如 ...
- Node 的fs模块
这个fs.readdir路径要加上__dirname 找到绝对路径 否则会报错 { Error: ENOENT: no such file or directory, scandir '/User ...
- <form> 标签的 enctype 属性
值 描述 application/x-www-form-urlencoded 在发送前编码所有字符(默认) multipart/form-data 不对字符编码.在使用包含文件上传控件的表单时,必须使 ...