poj1080 - Human Gene Functions (dp)
题面
It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been interested in identifying human genes and determining their functions, because these can be used to diagnose human diseases and to design new drugs for them.
题意
在两个字符串中,添加'-',使得长度相同,并且对应的权值和最大.
注意两个'-' 不能对应
思路
转换为lcs问题,类似的地方在于,求出对应最大的权值,但是同时考虑不再lcs里面的,就是和'-'相对应
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cerr<<#x<<" = "<<x<<endl;
#define debug(a, x) cerr<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define lson l,mid,ls
#define rson mid+1,r,rs
#define ls (rt<<1)
#define rs ((rt<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int loveisblue = 486;
const int maxn = 205;
const int maxm = 100086;
const int inf = 0x3f3f3f3f;
const ll Inf = 999999999999999999;
const int mod = 1000000007;
const double eps = 1e-6;
const double pi = acos(-1);
const int mat[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,5}
};
int get_id(char c){
if(c=='A'){
return 0;
}else if(c=='C'){
return 1;
}else if(c=='G'){
return 2;
}else if(c=='T'){
return 3;
}else{
return 4;
}
}
char s1[maxn],s2[maxn];
int dp[maxn][maxn];
int main() {
ios::sync_with_stdio(true);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int T;
scanf("%d",&T);
while (T--){
int len1,len2;
scanf("%d%s",&len1,s1+1);
scanf("%d%s",&len2,s2+1);
for(int i=0;i<=len1;i++){
for(int j=0;j<=len2;j++){
dp[i][j]=-inf;
}
}
dp[0][0]=0;
for(int i=1;i<=len1;i++)
dp[i][0]=dp[i-1][0]+mat[get_id(s1[i])][get_id('-')];
for(int i=1;i<=len2;i++)
dp[0][i]=dp[0][i-1]+mat[get_id(s2[i])][get_id('-')];
for(int i=1;i<=len1;i++){
for(int j=1;j<=len2;j++){
dp[i][j]=max(dp[i][j],dp[i-1][j-1]+mat[get_id(s1[i])][get_id(s2[j])]);
dp[i][j]=max(dp[i][j],dp[i-1][j]+mat[get_id(s1[i])][get_id('-')]);
dp[i][j]=max(dp[i][j],dp[i][j-1]+mat[get_id(s2[j])][get_id('-')]);
}
}
printf("%d\n",dp[len1][len2]);
}
return 0;
}
poj1080 - Human Gene Functions (dp)的更多相关文章
- POJ1080 Human Gene Functions(LCS)
题目链接. 分析: 和 LCS 差不多. #include <iostream> #include <cstdio> #include <cstdlib> #inc ...
- POJ1080 Human Gene Functions 动态规划 LCS的变形
题意读了半年,唉,给你两串字符,然后长度不同,你能够用'-'把它们补成同样长度,补在哪里取决于得分,它会给你一个得分表,问你最大得分 跟LCS非常像的DP数组 dp[i][j]表示第一个字符串取第i个 ...
- Human Gene Functions(dp)
http://poj.org/problem?id=1080 #include <stdio.h> #include <stdlib.h> #include <strin ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- 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(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 ...
- poj1080--Human Gene Functions(dp:LCS变形)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17206 Accepted: ...
- 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 ...
随机推荐
- Mysql里查询字段为Json格式的数据模糊查询以及分页方法
public void datagrid(CustomFormEntity customForm,HttpServletRequest request, HttpServletResponse res ...
- 总结 ESP8266 RTOS 开发环境搭建
总结 ESP8266 RTOS 开发环境搭建 仔细看官方文档. 必须一步一步操作. 不要想当然,以为 make 就可以. 忽略编译警告,除非是错误. 工具链必须使用官方提供的. 多看看 Issues ...
- iOS 9 学习系列:UIStack View
http://www.cocoachina.com/ios/20150921/13492.html 在 iOS9 中,Apple 引入了 UIStackView,他让你的应用可以通过简单的方式,纵向或 ...
- Apache CarbonData1.3简介
CarbonData是一种高性能大数据存储方案,支持快速过滤查找和即席OLAP分析,已在20+企业生产环境上部署应用,其中最大的单一集群数据规模达到几万亿.针对当前大数据领域分析场景需求各异而导致的存 ...
- weixin 微信开放平台 微信公众平台
官网地址入口 微信小程序 https://mp.weixin.qq.com/ appid and openid not match 1.appid :是公众号的ID. 2.openid:关注公众号生成 ...
- @codeforces - 932F@ Escape Through Leaf
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 个点的树(标号1~n),以结点 1 为根.每个结点 ...
- js原生复习2.0
// 1.闭包的作用// 实现共有变量,函数累加器的实现// 可以做缓存以及储存结构// 可以实现封装,实现属性私有化// 模块开发,防止全局污染// var name = 123;// var in ...
- LeetCode73 Set Matrix Zeroes
题目: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.(Me ...
- Mysql 数据库优化(一)
一 避免网页访问错误 1 数据库连接timeout产生页面5xx错误 2 慢查询造成页面无法加载 3 阻塞造成数据无法提交 二 增加数据库的稳定性 三 优化用户体验 1 流畅的页面访问速度 2 良好 ...
- python元组和range
1.元组 1)元组介绍 元组: 俗称不可变的列表.⼜被成为只读列表, 元组也是python的基本数据类型之⼀, ⽤⼩括号括起来, ⾥⾯可以放任何数据类型的数据, 查询可以. 循环也可以. 切片也可以. ...