zoukankan      html  css  js  c++  java
  • 相似基因

    相似基因

    题目描述

    大家都知道,基因可以看作一个碱基对序列。它包含了4种核苷酸,简记作A,C,G,T。生物学家正致力于寻找人类基因的功能,以利用于诊断疾病和发明药物。

    在一个人类基因工作组的任务中,生物学家研究的是:两个基因的相似程度。因为这个研究对疾病的治疗有着非同寻常的作用。两个基因的相似度的计算方法如下:

    对于两个已知基因,例如AGTGATG和GTTAG,将它们的碱基互相对应。当然,中间可以加入一些空碱基-,例如:

    A

    G

    T

    G

    A

    T

    -

    G

    -

    G

    T

    -

    -

    T

    A

    G

    这样,两个基因之间的相似度就可以用碱基之间相似度的总和来描述,碱基之间的相似度如下表所示:




    那么相似度就是:(-3)+5+5+(-2)+(-3)+5+(-3)+5=9。因为两个基因的对应方法不唯一,例如又有:

    A

    G

    T

    G

    A

    T

    G

    -

    G

    T

    T

    A

    -

    G

    相似度为:(-3)+5+5+(-2)+5+(-1)+5=14。规定两个基因的相似度为所有对应方法中,相似度最大的那个。

    输入

    共两行。每行首先是一个整数,表示基因的长度;隔一个空格后是一个基因序列,序列中只含A,C,G,T四个字母。1<=序列的长度<=100。

    输出

    仅一行,即输入基因的相似度。

    样例输入

    7 AGTGATG
    5 GTTAG
    

    样例输出

    14
    分析:类似最长公共子序列的dp;
    代码:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    const int maxn=1e3+10;
    const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
    using namespace std;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    int n,m,k,t,cost[maxn][maxn],dp[maxn][maxn];
    string a,b;
    void init()
    {
        cost['A']['A']=5;
        cost['A']['C']=-1;
        cost['A']['G']=-2;
        cost['A']['T']=-1;
        cost['A']['-']=-3;
     
        cost['C']['C']=5;
        cost['C']['A']=-1;
        cost['C']['G']=-3;
        cost['C']['T']=-2;
        cost['C']['-']=-4;
     
        cost['G']['G']=5;
        cost['G']['A']=-2;
        cost['G']['C']=-3;
        cost['G']['T']=-2;
        cost['G']['-']=-2;
     
        cost['T']['T']=5;
        cost['T']['A']=-1;
        cost['T']['C']=-2;
        cost['T']['G']=-2;
        cost['T']['-']=-1;
     
        cost['-']['-']=inf;
        cost['-']['A']=-3;
        cost['-']['C']=-4;
        cost['-']['G']=-2;
        cost['-']['T']=-1;
    }
    int main()
    {
        int i,j;
        init();
        cin>>n>>a>>m>>b;
        rep(i,1,n)dp[i][0]=dp[i-1][0]+cost[a[i-1]]['-'];
        rep(i,1,m)dp[0][i]=dp[0][i-1]+cost['-'][b[i-1]];
        rep(i,0,n-1)rep(j,0,m-1)
        {
            dp[i+1][j+1]=max({dp[i][j]+cost[a[i]][b[j]],dp[i+1][j]+cost['-'][b[j]],dp[i][j+1]+cost[a[i]]['-']});
        }
        printf("%d
    ",dp[n][m]);
        //system("pause");
        return 0;
    }
  • 相关阅读:
    【BZOJ3190】[JLOI2013]赛车 单调栈+几何
    【BZOJ2738】矩阵乘法 整体二分
    PR 批量导入
    JAVA 水果机游戏及编码
    sap 图标查看
    ABAP 给动态变量赋值
    abap 数字移动小游戏
    FI模块与SD、MM的接口配置方法
    信用控制增强
    SAP-财务知识点
  • 原文地址:https://www.cnblogs.com/dyzll/p/5775240.html
Copyright © 2011-2022 走看看