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 ...
随机推荐
- MySql5.1在Win7下的安装与重装问题的解决
痛苦啊痛苦,我也不知道这两天怎么了.上班没有精神,还打瞌睡,下班后又感觉很累.精力集中不起来. 这篇花了我好久的时间,我效率这么差,~\(≧▽≦)/~. 软件包下载 首先单击mysql-5.1.53- ...
- PHP学习笔记十四【面向对象】
<?php class Cat{ public $name; public $age; public $color; } //创建一个对象 $cat1=new Cat(); $cat1-> ...
- .Net中如何使用MySql连接池
提供一份官方的译文.翻译也挺辛苦的!! 6.4 Using Connector/Net with Connection Pooling 6.4在Connector/Net中使用连接池 The Conn ...
- Mysql JOIN优化。
join性能自行百度,google 数据60w+,这里我只测试了一个limit , ) ,) AS C LEFT JOIN table2 AS B ON C.e_id=B.id; ) ,;
- ThinkPHP 类似Yii的Gii生成Model的功能。
ThinkPHP 类似Yii的Gii生成Model的功能.自动生成ThinkPhp 3.1 的基础模型.. #!/usr/bin/env php <?php /** * * THINKPHP 基 ...
- JAVA的网络编程【转】
JAVA的网络编程[转] Posted on 2009-12-03 18:04 火之光 阅读(93441) 评论(20) 编辑 收藏 网络编程 网络编程对于很多的初学者来说,都是很向往的一种编程技能, ...
- 'ManyRelatedManager' object is not iterable
先看下面的代码: class Worker(models.Model): departments = moels.ManyToManyField(Department, verbose_name=u& ...
- UVA 10943 How do you add?
设函数 f(k)(n); 则: f(1)(n)=1; f(2)(n)=f(1)(0)+f(1)(1)+f(1)(2)+...+f(1)(n); f(3)(n)=f(2)(0)+f(2)(1)+f(2) ...
- Azure File SMB3.0文件共享服务(1)
Azure Storage File是Azure推出的文件共享服务,目前的版本同时支持SMB 2.1和SMB 3.0协议.文件共享服务非常适合那些希望把自己数据中心中使用文件共享的应用程序,在云端需要 ...
- VC连接SQL server2005
VC连接SQL server2005 1.创建一个MFC对话框程序 界面如下 2.创建一个成员变量 这个成员变量用于连接数据库 3.响应按钮函数OnButton1() 在响应函数里主要有三个函数 函数 ...