【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 ...
随机推荐
- Java虚拟机详解02----JVM内存结构
主要内容如下: JVM启动流程 JVM基本结构 内存模型 编译和解释运行的概念 一.JVM启动流程: JVM启动时,是由java命令/javaw命令来启动的. 二.JVM基本结构: JVM基本结构图: ...
- js知识体系的梳理一
今天简单的总结了js的一些东西,梳理下整个体系,每一次的总结都会有不同的收获:js总结一一.[获取元素]: 1.通过ID: var oBtn=document.getElementById('btn1 ...
- 30Springd的包扫描——<context:component-scan base-package=” ”/>
在context中配置 如:在base-package指明一个包: <context:component-scan base-package="cn.edu.dao"/> ...
- 11SpringMvc_一个Action中,写多个类似的业务控制方法
我们要实现这么一个功能: 编写两个表单,提交到同一个Action中的不同的处理方法中.比如注册和登录,都提交到UserAction这个控制类中.但是这两个提交由userAction这个控制类不同的方法 ...
- salt-ssh
1.生产---测试--开发 salt-runners salt-run manage.status#显示当前up或down的minion salt-run manage.down salt-run m ...
- C语言 常用的时间函数
//时间函数的使用 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include& ...
- 检测到 LoaderLock:DLL"XXXX"正试图在OS加载程序锁内执行
解决方法: ctrl+D+E或alt+ctl+e或使用菜单调试——>异常——>异常窗口——>Managed Debugging Assistants——>去掉LoaderLoc ...
- 小程序基础02:全局配置app.json
1.配置 我们使用app.json文件来对来微信小程序进行全局配置. 作用:他决定了页面文件的路径,窗口表现,设置网络超时时间,设置多tab等 每一个小程序页面也可以使用 .json 文件来对本页面的 ...
- Android 动画之AlphaAnimation应用详解
窗口的动画效果,淡入淡出什么的,有些游戏的欢迎动画,logo的淡入淡出效果就使用AlphaAnimation.AlphaAnimation(0.01f, 1.0f); 从0.01f到1.0f渐变.学过 ...
- Android -- 创建数据库到SD卡
SQLite 系统自带的SQLite是通过SQLiteOpenHelper实现的,而SQLiteOpenHelper是将数据库存储到/data/data/包名/databasas,这样做的话在没有ro ...