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 ...
随机推荐
- 使用SOAPUI测试WEBAPI接口
其实很简单,用起来也挺方便的. 首先,先去百度下SoapUI 下载,下载安装好后,打开软件. 1.新建一个项目 点击 Create Empty Project 按钮后,会自动新建一个项目,名字默认为: ...
- HTML之学习笔记(二)颜色体系
html页面的颜色表示法有三种:英文表示,16进制表示和10进制表示.颜色通过三原色即红.绿.蓝三种按比例混合而成,如红色的10进制表示为255,0,0,即按照红色.绿色.蓝色的格式,权值取0~255 ...
- PHP学习笔记二
<?php //布尔类型 $a=true; //值不区分大小写 $b=false;//整型0,浮点数0.0,空字符串,不包括任何元素的数组,空对象,null都表示false $c=0; if($ ...
- NSArray数组的学习总结
1.不可变数组NSArray NSArray是不可变的,而且只能储存Object-c对象.另外,数组的最后一个元素一定是nil,表示结束. 注:这些集合类只能收集cocoa对象(NSOjbect对象) ...
- C语言undefined behaviour未定义行为
C语言中的未定义行为(Undefined Behavior)是指C语言标准未做规定的行为.同时,标准也从没要求编译器判断未定义行为,所以这些行为有编译器自行处理,在不同的编译器可能会产生不同的结果,又 ...
- java中的xpath,读取xml文档。
1,入门 XPath即为XML路径语言(XML Path Language),它是一种用来确定XML文档中某部分位置的语言. XPath基于XML的树状结构,提供在数据结构树中找寻节点的能力.起初 X ...
- setTimeout setInterval 带参数的问题
转载http://www.jb51.net/article/36233.htm 在JS中无论是setTimeout还是setInterval,在使用函数名作为调用句柄时都不能带参数,而在许多场合必须要 ...
- Oracle EBS-SQL (INV-6):检查监督帐户别名处理.sql
select MSI.SEGMENT1 项目编码, MSI.DESCRIPTION ...
- Delphi与Javascript的交互
网络上也有人写了关于Delphi与Javascript的文章,其大多数使用ScriptControl等,均无法达到与Delphi自身融合的效果.我也是在翻阅自己的组件库的时候发现了这个以前收集来的代码 ...
- SQL Server 2008 对XML 数据类型操作
原文 http://www.cnblogs.com/qinjian123/p/3240702.html 一.前言 从 SQL Server 2005 开始,就增加了 xml 字段类型,也就是说可以直接 ...