题目链接: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的更多相关文章

  1. POJ 1080:Human Gene Functions LCS经典DP

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18007   Accepted:  ...

  2. poj 1080 Human Gene Functions(lcs,较难)

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19573   Accepted:  ...

  3. Human Gene Functions

    Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...

  4. 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 ...

  5. poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17805   Accepted:  ...

  6. 【POJ 1080】 Human Gene Functions

    [POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...

  7. POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)

    题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...

  8. poj1080 - Human Gene Functions (dp)

    题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...

  9. 杭电20题 Human Gene Functions

    Problem Description It is well known that a human gene can be considered as a sequence, consisting o ...

  10. 刷题总结——Human Gene Functions(hdu1080)

    题目: Problem Description It is well known that a human gene can be considered as a sequence, consisti ...

随机推荐

  1. 计算机网络相关知识(http状态码 && 首部字段)

    计算机网络相关知识 计算机网络的知识还是非常重要的, 这里做一个简单的总结. 推荐阅读文章:http://www.cnblogs.com/TankXiao/archive/2012/02/13/234 ...

  2. nodejs(二) --- 重要知识点回顾

    1. 运行一个nodejs文件, 如一个js文件中只含有console.log("hello world");的文件,我们再git里运行node,即 node hello.js 即 ...

  3. [转]实例化SqlParameter时,如果是字符型,一定要指定size属性

    转自:http://bbs.csdn.net/topics/380155255 以前在实例化SqlParameter时,通常都是用下面的语句,没有设置size属性: new SqlParameter( ...

  4. C#(Winform)的SaveFileDialog(文件保存对话框)控件使用

       #region 保存对话框   private void ShowSaveFileDialog()   {         //string localFilePath, fileNameExt ...

  5. php之mongodb插入数据后如何返回当前插入记录ID

    <?php /** *插入记录 *参数: *$table_name:表名 *$record:记录 * *返回值: *成功:true *失败:false */ function insert($t ...

  6. Docker进阶

    Docker进阶 Docker容器命名与重命名 命名 docker run -it -p 80:80 --name containerName img:tag /bin/bash 重命名 docker ...

  7. BNU34058——干了这桶冰红茶!——————【递推】

    干了这桶冰红茶! Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class nam ...

  8. [转]<加密算法c#>——— 3DES加密之ECB模式 和 CBC模式

    本文转自:http://www.cnblogs.com/qq278360339/archive/2013/06/05/3119222.html 最近 一个项目.net 要调用JAVA的WEB SERV ...

  9. 小程序中搜索文件,阅览pdf,分享文件链接,评论表情符号

    小程序中搜索文件,阅览pdf,分享文件链接,评论表情符号 https://blog.csdn.net/hotqin888/article/details/84111389 小程序中打开网页和pdf h ...

  10. /Date(1410019200000+0800)/如何转换为date对象

    <script type="text/javascript">var s = '/Date(1410019200000+0800)/ '; s.replace(/Dat ...