• poj 1080 基因组(LCS)


    Human Gene Functions
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 19376   Accepted: 10815

    Description

    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. 

    A human gene can be identified through a series of time-consuming biological experiments, often with the help of computer programs. Once a sequence of a gene is obtained, the next job is to determine its function. 
    One of the methods for biologists to use in determining the function of a new gene sequence that they have just identified is to search a database with the new gene as a query. The database to be searched stores many gene sequences and their functions – many researchers have been submitting their genes and functions to the database and the database is freely accessible through the Internet. 

    A database search will return a list of gene sequences from the database that are similar to the query gene. 
    Biologists assume that sequence similarity often implies functional similarity. So, the function of the new gene might be one of the functions that the genes from the list have. To exactly determine which one is the right one another series of biological experiments will be needed. 

    Your job is to make a program that compares two genes and determines their similarity as explained below. Your program may be used as a part of the database search if you can provide an efficient one. 
    Given two genes AGTGATG and GTTAG, how similar are they? One of the methods to measure the similarity 
    of two genes is called alignment. In an alignment, spaces are inserted, if necessary, in appropriate positions of 
    the genes to make them equally long and score the resulting genes according to a scoring matrix. 

    For example, one space is inserted into AGTGATG to result in AGTGAT-G, and three spaces are inserted into GTTAG to result in –GT--TAG. A space is denoted by a minus sign (-). The two genes are now of equal 
    length. These two strings are aligned: 

    AGTGAT-G 
    -GT--TAG 

    In this alignment, there are four matches, namely, G in the second position, T in the third, T in the sixth, and G in the eighth. Each pair of aligned characters is assigned a score according to the following scoring matrix. 

    denotes that a space-space match is not allowed. The score of the alignment above is (-3)+5+5+(-2)+(-3)+5+(-3)+5=9. 

    Of course, many other alignments are possible. One is shown below (a different number of spaces are inserted into different positions): 

    AGTGATG 
    -GTTA-G 

    This alignment gives a score of (-3)+5+5+(-2)+5+(-1) +5=14. So, this one is better than the previous one. As a matter of fact, this one is optimal since no other alignment can have a higher score. So, it is said that the 
    similarity of the two genes is 14.

    Input

    The input consists of T test cases. The number of test cases ) (T is given in the first line of the input file. Each test case consists of two lines: each line contains an integer, the length of a gene, followed by a gene sequence. The length of each gene sequence is at least one and does not exceed 100.

    Output

    The output should print the similarity of each test case, one per line.

    Sample Input

    2 
    7 AGTGATG 
    5 GTTAG 
    7 AGCTATT 
    9 AGCTTTAAA 

    Sample Output

    14
    21 

    Source

     dp[i][j]:长度为i的dna,a与长度为j的dna,b具有的最大价值
    每个问题含有三种决策:
    T1: 让ai与bj匹配,则dp[i][j]=dp[i-1][j-1]+ai-bj;
    T2:让ai单独出来与空格匹配,则dp[i][j]=dp[i-1][j]+ai-' ';
    T3:让bj单独出来与空格匹配,dp[i][j]=dp[i][j-1]+' '-bj;
    dp[i][j]=max{T1,T2,T3};
    LCS变形,状态转移:dp[i,j]=max(dp[i-1,j-1]+dis[ai,bj],dp[i,j-1]+dis[_,b[j]],dp[i-1,j]+dis[ai,_])    //dis便是题目所给的表格'_'代表空位,因为可以让字母与空相对计算价值,所以为了得到最大价值,方程也发生改变
    ps:  第一次使用map
    代码:
     #include<iostream>
    #include<cstring>
    #include<map>
    #include<cstdio>
    using namespace std;
    int Max(int a,int b,int c)
    {return max(max(a,b),max(b,c));}
    int main()
    {    
        char a[105],b[105];
        int i,j,dp[105][105];
        int t,n1,n2,v[10][10]={{5,-1,-2,-1,-3},{-1,5,-3,-2,-4},{-2,-3,5,-2,-2},{-1,-2,-2,5,-1},{-3,-4,-2,-1,0}};     //储存表格
        map<char,int> pic;
        pic['A']=0,pic['C']=1,pic['G']=2,pic['T']=3,pic['-']=4;                                                                                  //利用map,方便方程的表示
        cin>>t;
        while (t--){
            dp[0][0];
    scanf("%d%s",&n1,a+1);
    scanf("%d%s",&n2,b+1);    
            for (i=1;i<=n1;i++){
                dp[i][0]=dp[i-1][0]+v[pic[a[i]]][pic['-']];
                for (j=1;j<=n2;j++){
               dp[0][j]=dp[0][j-1]+v[pic['-']][pic[b[j]]];
     dp[i][j] =Max(dp[i-1][j-1] + v[pic[a[i]]][pic[b[j]]],dp[i-1][j] + v[pic[a[i]]][pic['-']],dp[i][j-1] + v[pic['-']][pic[b[j]]]);
                }
            }        
            printf("%d ",dp[n1][n2]);
        }
        return 0;
    }
     
  • 相关阅读:
    js 绑定事件没有触发的离奇事件
    TweenMax 中 tweenTo
    TweenMax 中 to,staggerTo 的第 4 、5 个参数
    Mongodb 数据库操作
    cocos2dx骨骼动画Armature源码分析(一)
    TexturePacker大图还原成小图工具带源码
    通过JavaScript原型链理解基于原型的编程
    webpack 之(25) output配置详解
    webpack 之(24) entry配置详解
    webpack 之(23) 优化配置 总结
  • 原文地址:https://www.cnblogs.com/zzqc/p/6386563.html
Copyright © 2020-2023  润新知