题面

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)的更多相关文章

  1. POJ1080 Human Gene Functions(LCS)

    题目链接. 分析: 和 LCS 差不多. #include <iostream> #include <cstdio> #include <cstdlib> #inc ...

  2. POJ1080 Human Gene Functions 动态规划 LCS的变形

    题意读了半年,唉,给你两串字符,然后长度不同,你能够用'-'把它们补成同样长度,补在哪里取决于得分,它会给你一个得分表,问你最大得分 跟LCS非常像的DP数组 dp[i][j]表示第一个字符串取第i个 ...

  3. Human Gene Functions(dp)

    http://poj.org/problem?id=1080 #include <stdio.h> #include <stdlib.h> #include <strin ...

  4. poj 1080 Human Gene Functions(dp)

    题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...

  5. POJ 1080:Human Gene Functions LCS经典DP

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18007   Accepted:  ...

  6. poj 1080 Human Gene Functions(lcs,较难)

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19573   Accepted:  ...

  7. Human Gene Functions

    Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...

  8. poj1080--Human Gene Functions(dp:LCS变形)

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17206   Accepted:  ...

  9. 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 ...

随机推荐

  1. Ubuntu 16.04下OLSR协议安装教程

    OLSR是根据MANET的要求,在传统的LS(Link state)协议的基础上优化的. OLSR中的关键概念是多点转播(MPRs),MPRs是在广播洪泛的过程中挑选的转发广播的节点.传统的链路状态协 ...

  2. 「WC2018」即时战略

    「WC2018」即时战略 考虑对于一条链:直接随便找点,然后不断问即可. 对于一个二叉树,树高logn,直接随便找点,然后不断问即可. 正解: 先随便找到一个点,问出到1的路径 然后找别的点,考虑问出 ...

  3. 【windows系统下的navicat与ubuntu中的mysql的连接方法】

    ##红色代码直接复制到终端 1.首先,终端上mysql -u root -p,进入你的mysql数据库,操作数据库use mysql.2.切换root权限:sudo -i3.对root授权,输入:gr ...

  4. IDEA切换git分支

    查看当前所在分支 场景:在多人开发中,需要在主分支的基础上创建一些分支分配给小团队或个人去开发,然后小分支上的小功能开发完毕之后,再merge(合并)到主分支. 1.查看当前所在的分支 下图1.1中是 ...

  5. 复习一下jdbc原始封装

    JDBC连接数据库 •创建一个以JDBC连接数据库的程序,包含7个步骤: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这通过java.l ...

  6. 2019-10-26-dotnet-core-发布只有一个-exe-的方法

    title author date CreateTime categories dotnet core 发布只有一个 exe 的方法 lindexi 2019-10-26 8:42:7 +0800 2 ...

  7. 【NS2】常用资源(转载)

    (一). NS常用基本网站 1. 寻求问题答案最好的地方.    http://mailman.isi.edu/pipermail/ns-users/ 2. 柯老师的网站,包含很多非常实用资源:安装, ...

  8. Mybatis表关联多对多

    创建表 创建表对应的 JavaBean 对象 package com.tanlei.newer.model; import java.util.List; /** * @author:Mr.Tan * ...

  9. 关于Lattice Planner规划算法的若干问答

    Apollo问答 | 关于Lattice Planner规划算法的若干问答   上周,我们在Apollo开发者交流群内做了关于Lattice Planner的分享.这里,我们将社群分享里开发者提出的问 ...

  10. [kuangbin带你飞]专题九 连通图E POJ 3177 Redundant Paths

    这个题最开始我想的是,直接缩点求双连通分量,连接这些双联通分量不就行了吗? 但是其实是不对的,双连通内部双联通,我们如果任意的连接一条边在这些双联通分量之间,他们之间有没有桥其实并不知道. 我应该是求 ...