zoj1027 Human Gene Functions
一道动态规划,两个串进行匹配,不同字母匹配的值不一样,也可以和空格匹配(空格不能与空格匹配),求最大的匹配值。
数据很弱,每个串都在100以内。
定义dp[i][j]为第一个串前i个数和第二个串前j个数已匹配的匹配值
有三种情况:1.第i个和第j个匹配
2.第i个和‘-’匹配
3.第j个和‘-’匹配
注意合理初始化
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
using namespace std;
int g[5][5]={{5,-1,-2,-1,-3},{-1,5,-3,-2,-4},{-2,-3,5,-2,-2},{-1,-2,-2,5,-1},{-3,-4,-2,-1,0}};
char str1[105];
char str2[105];
map<char,int> m;
int cas;
int dp[105][105];//前i个数和前j个数已匹配的情况
int main()
{
// freopen("input.txt","r",stdin);
int len1,len2;
scanf("%d",&cas);
m['A']=0;
m['C']=1;
m['G']=2;
m['T']=3;
m['-']=4;
while(cas--)
{
scanf("%d%s",&len1,str1);
scanf("%d%s",&len2,str2);
dp[0][0]=0;
for(int i=1;i<=len1;i++)
dp[i][0]=dp[i-1][0]+g[m[str1[i-1]]][4];
for(int i=1;i<=len2;i++)
dp[0][i]=dp[0][i-1]+g[4][m[str2[i-1]]];
for(int i=1;i<=len1;i++)
for(int j=1;j<=len2;j++)
{
int t1=dp[i-1][j-1]+g[m[str1[i-1]]][m[str2[j-1]]];
int t2=dp[i-1][j]+g[m[str1[i-1]]][4];
int t3=dp[i][j-1]+g[4][m[str2[j-1]]];
dp[i][j]=max(t1,max(t2,t3));
}
printf("%d\n",dp[len1][len2]);
}
}
zoj1027 Human Gene Functions的更多相关文章
- 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(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- 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 -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- 杭电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 ...
随机推荐
- web前端技术归类
1.以屏幕可用宽和高的百分比来定义弹出框的宽和高 var trueWidth = $(top.window).width() * 0.9;var trueHeight = $(top.window). ...
- jfreechart中文乱码问题解决方案(转)
参考网址:http://zhidao.baidu.com/link?url=y88rR1_aAHaFofonx9o_IaEu87MpkTQImsqDcy587eG55JkfQV6EzzzloIgXuQ ...
- 高效批量更新 sql 字段的值(从一个表向另一个表更新)
里给出一种更高效.简洁的做法,批量更新SQL ,一句SQL就可以替代麻烦的循环过程,有MS SQLServer.Oracle.DB2下的写法--关键点:t4和t1是同一个table,primary k ...
- sqlite在c++中的使用方法
1.需要下载的文件 http://pan.baidu.com/s/1c06NpzM 2.执行文件shell的编译 3.在c++中如何使用 #include <stdio.h> # ...
- Android性能优化建议
1.减少View树的高度(多层嵌套) 2.使用<include>重用layout 3.使用<ViewStub>实现View的延迟加载 作用范围:当这个布局在初始化加载时候,不需 ...
- Razor学习(二)@Html标签
原文链接:http://blog.csdn.net/pasic/article/details/7093802 只是因为原文作者说的东西,还有很多作为基础知识的东西,我都没有掌握,所以总结在这里,蓝字 ...
- JVM启动过程——JVM之一
JVM是Java程序运行的环境,同时是一个操作系统的一个应用程序进程,因此它有自己的生命周期,也有自己的代码和数据空间. JVM体系主要是两个JVM的内部体系结构分为三个子系统和两大组件,分别是:类装 ...
- Ubuntu 12.04设置豆沙绿
首先确保已安装dconf-editor sudo apt-get install dconf-tools 然后打开dconf-editor 找到:org – gnome -desktop – ...
- 在WPF中自定义你的绘制(一)
原文:在WPF中自定义你的绘制(一) 在WPF中自定义你的绘制(一) ...
- C++之单元测试
以前编写程序从没有做过单元测试的工作,所以在后期会花很多时间去纠错,这也就是软件工程中的2:8定律.最近要完成一个项目,要求要对系统中的主类和主函数作出单元测试的保证,才去查找了相关方面的资料,看过后 ...