• poj1080


    题面
    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
    ",dp[len1][len2]);
        }
    
        return 0;
    }
    
    
  • 相关阅读:
    清除大文本中的html标签
    页面中富文本的使用
    artDialog的几种基本使用
    SQL基础-->层次化查询(START BY ... CONNECT BY PRIOR)[转]
    Struts2
    js中window.location的用法
    keycode键盘 按键
    jQuery升级踩坑之路
    生成唯一随机码的方法及优缺点分析
    百度API的经历,怎样为多个点添加带检索功能的信息窗口
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/11569735.html
Copyright © 2020-2023  润新知