【poj1080】 Human Gene Functions
http://poj.org/problem?id=1080 (题目链接)
题意
给出两个只包含字母ACGT的字符串s1、s2,可以在两个字符串中插入字符“-”,使得s1与s2的相似度最大。
Solution
动态规划。
用f[i][j]表示字符串s1前i位和s2前j位的最大相似度,转移很简单,直接看程序吧,边界条件要注意,当i=0或j=0时,就等于是在长度等于0的字符串中全部插入“-”,使得两字符串长度相等的相似度。打个表预处理出每两个字符的相似度比较方便后面的操作。
代码
// poj1080
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf 2147483640
#define Pi 3.1415926535898
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; int f[110][110],w[510][510],T,n1,n2;
char s1[110],s2[110]; int main() {
scanf("%d",&T);
w['A']['A']=5;w['A']['C']=-1;w['A']['G']=-2;w['A']['T']=-1;w['A']['-']=-3;
w['C']['A']=-1;w['C']['C']=5;w['C']['G']=-3;w['C']['T']=-2;w['C']['-']=-4;
w['G']['A']=-2;w['G']['C']=-3;w['G']['G']=5;w['G']['T']=-2;w['G']['-']=-2;
w['T']['A']=-1;w['T']['C']=-2;w['T']['G']=-2;w['T']['T']=5;w['T']['-']=-1;
w['-']['A']=-3;w['-']['C']=-4;w['-']['G']=-2;w['-']['T']=-1;w['-']['-']=0;
while (T--) {
memset(f,0,sizeof(f));
scanf("%d%s%d%s",&n1,s1+1,&n2,s2+1);
f[0][0]=0;
for (int i=0;i<=n1;i++) f[i][0]=w[s1[i]]['-']+f[i-1][0];
for (int i=0;i<=n2;i++) f[0][i]=w['-'][s2[i]]+f[0][i-1];
for (int i=1;i<=n1;i++)
for (int j=1;j<=n2;j++) {
f[i][j]=f[i-1][j-1]+w[s1[i]][s2[j]];
f[i][j]=max(f[i][j],f[i-1][j]+w[s1[i]]['-']);
f[i][j]=max(f[i][j],f[i][j-1]+w['-'][s2[j]]);
}
printf("%d\n",f[n1][n2]);
}
return 0;
}
【poj1080】 Human Gene Functions的更多相关文章
- 【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——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- 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 LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- POJ 1080 Human Gene Functions 【dp】
题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...
- poj1080 - Human Gene Functions (dp)
题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
随机推荐
- 第2章 面向对象的设计原则(SOLID):1_单一职责原则(SRP)
1. 单一职责原则(Single Responsibility Principle,SRP) 1.1 单一职责的定义 (1)定义:一个类应该仅有一个引起它变化的原因.这里变化的原因就是所说的“职责”. ...
- java 8-7 接口
1. 接口的特点: A:接口用关键字interface表示 interface 接口名 {} B:类实现接口用implements表示 class 类名 implements 接口名 {} C:接口不 ...
- 07Spring_bean属性的依赖注入-重点@Autowriter
在spring2.5 版本,没有提供基本类型属性注入 ,但是spring3.0引入注解@Value 所以在Spring3.0中属性的注入只可以这么写.
- 【转】【C#】【Thread】Mutex 互斥锁
Mutex:互斥(体) 又称同步基元. 当创建一个应用程序类时,将同时创建一个系统范围内的命名的Mutex对象.这个互斥元在整个操作系统中都是可见的.当已经存在一个同名的互斥元时,构造函数将会输出一个 ...
- iframe在ipad safari的显示
今 天要在web中嵌套一个网址或本地HTML,用到了iframe,在电脑上设置scrolling=‘auto’,宽度高度,会有滚动条出现.而在 ipad上会全部显示整个网页的宽度高度.scrollin ...
- C# 结构体
1,结构体不能出现在继承关系中,除了继承接口. 结构体不能继承类或结构,也不能被类或结构继承,只可以继承接口. 2,struct不能定义默认构造函数(无参构造函数),也不能定义析构函数.class对这 ...
- IBatis.Net学习笔记七--日志处理
IBatis.Net中提供了方便的日志处理,可以输出sql语句等调试信息. 常用的有两种:1.输出到控制台: <configSections> <sectionGroup ...
- 团购、定时抢购倒计时js版
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org ...
- windows 7 安装 scrapy
基于64位 win7 系统 先到 http://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载四个 wheel 文件: 1. lxml-3.4.4-cp27-none-w ...
- 九度oj-1003-Java
题目描述: 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开. 现在请计算A+B的结果,并以正常形式输出. 输入: 输入包含多组数据数据,每组数据占一行,由两 ...