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 ...
随机推荐
- 记录ASP.NET页面表单初始状态(主要是为了前台可以根据这个判断页面是否变动了)
把页面表单状态记录到HiddenField中. 这里只提供后台代码, 前台逻辑根据需求自由定义. 存放值的ViewState: protected Dictionary<string, stri ...
- 一些实用的CSS Media Query代码片段,个人采集
CSS3的出现让响应式Web设计变得简单,CSS3提供了强大的media queries,允许你针对不同的条件设置不同的样式,可以在不修改页面内容的情况下,为不同设备提供不同的样式效果. 以下是一些C ...
- 将已有项目导入Gitlab
登陆GitLab,创建添加项目. 写入项目的基本信息,包括名称.描述.权限等等. cd existing_folder git init git remote add origin git@10.10 ...
- 使用SQLCipher加密数据库
Xcode中集成了免费的sqlite,但是不提供加密的模块,突然有一天,蛋疼的客户要求把数据进行加密,于是乎就寻找使用简单并且可以把数据迁移过度到加密数据库的框架. SQLCipher是第三方的开 ...
- (转)三角函数计算,Cordic 算法入门
由于最近要使用atan2函数,但是时间上消耗比较多,因而网上搜了一下简化的算法. 原帖地址:http://blog.csdn.net/liyuanbhu/article/details/8458769 ...
- Retrofit的使用
参照文档:http://gank.io/post/56e80c2c677659311bed9841 一.创建Retrofit mRetrofit = new Retrofit.Builder() .b ...
- java学习一目了然——IO
java学习一目了然--IO IO是java学习当中很重要的一部分.IO流实现数据的上传下载,即读写数据,包括输入和输出流,输入流指的是将数据以字符或字节形式从外部媒介比如文件.数据库等读取到内存中所 ...
- SQL Server 无法启动的 4 种原因
SQL Server 无法启动的原因定位.首先要知道SQL Server 启动的过程. 第一步: 读取注册表,创建log文件.检测硬件.初始化系统配置. 第二步: 启动系统数据库. 第三步: 准备好网 ...
- SQL连接方式(内连接,外连接,交叉连接)
1.内连接.左连接.右连接.全连接介绍 內连接仅选出两张表中互相匹配的记录.因此,这会导致有时我们需要的记录没有包含进来.内部连接是两个表中都必须有连接字段的对应值的记录,数据才能检索出来. 左连 ...
- Docker学习笔记之一,搭建一个JAVA Tomcat运行环境
Docker学习笔记之一,搭建一个JAVA Tomcat运行环境 前言 Docker旨在提供一种应用程序的自动化部署解决方案,在 Linux 系统上迅速创建一个容器(轻量级虚拟机)并部署和运行应用程序 ...