Human Gene Functions

Human Gene Functions 
Problem Description
It is well known that a human gene can be considered as a sequence,consisting of four nucleotides, which are simply denoted by fourletters, A, C, G, and T. Biologists have been interested inidentifying human genes and determining their functions, becausethese can be used to diagnose human diseases and to design newdrugs for them.

A human gene can be identified through a series of time-consumingbiological experiments, often with the help of computer programs.Once a sequence of a gene is obtained, the next job is to determineits function.
One of the methods for biologists to use in determining thefunction of a new gene sequence that they have just identified isto search a database with the new gene as a query. The database tobe searched stores many gene sequences and their functions manyresearchers have been submitting their genes and functions to thedatabase and the database is freely accessible through theInternet.

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

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

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

AGTGAT-G
-GT--TAG

In this alignment, there are four matches, namely, G in the secondposition, T in the third, T in the sixth, and G in the eighth. Eachpair of aligned characters is assigned a score according to thefollowing scoring matrix.


denotes that a space-space match is not allowed. The score of thealignment 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 differentpositions):

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, thisone 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 ) (Tis given in the first line of the input file. Each test caseconsists of two lines: each line contains an integer, the length ofa gene, followed by a gene sequence. The length of each genesequence is at least one and does not exceed 100.


Output
The output should print the similarity of each test case, one perline.


Sample Input
2
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA


Sample Output
14
21


Source

PKU

题意:就是给你两个(多组)字符串,求按照其给定对应关系所能得到的最大匹配值(字符串中间可以添加空格来实现最大的取值);这个题就是一个扩展的最大字符串匹配。
思路:
1、 s1取第i个字母,s2取“ - ”:dp[i][j] = dp[i-1,j] + dist[s1[i],'-'];
2、 s1取“ - ”,s2取第j个字母:dp[i][j] = dp[i,j-1] + dist['-',s2[j]];
3、 s1取第i个字母,s2取第j个字母:dp[i][j] = dp[i-1,j-1] +dist[s1[i],s2[j]]
即dp[i,j]=max( dp[i-1,j] + dist[s1[i],'-'],dp[i,j-1]+dist['-',s2[j]], dp[i-1,j-1]+dist[s1[i],s2[j]]);

c++ source code:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int dist[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, -100
};
int max (int a, int b, int c)
{
    int d = a > b ? a : b;
    return d > c ? d : c;
}
int main()
{
    int i, j, dp[101][101], len1, len2, t;
    char s1[101], s2[101];
    int a1[101], a2[101];
    scanf ("%d", &t);
    while (t--)
    {
        scanf ("%d%s%d%s", &len1, s1+1,&len2, s2+1);
        for (i = 1; i <= len1; i++)
        {
            if (s1[i] == 'A') a1[i] = 0;
            if (s1[i] == 'C') a1[i] = 1;
            if (s1[i] == 'G') a1[i] = 2;
            if (s1[i] == 'T') a1[i] = 3;
        }
        for (i = 1; i <= len2; i++)
        {
            if (s2[i] == 'A') a2[i] = 0;
            if (s2[i] == 'C') a2[i] = 1;
            if (s2[i] == 'G') a2[i] = 2;
            if (s2[i] == 'T') a2[i] = 3;
        }
        memset (dp, 0, sizeof (dp));
        for (i = 0; i <= len1; i++)
        {
            for (j = 0; j <= len2; j++)
            {
                if (i == 0 && j == 0) dp[i][j] =0;
                else if (j == 0 && i> 0) dp[i][j] = dp[i-1][j] + dist[a1[i]][4];
                else if (i == 0 && j> 0) dp[i][j] = dp[i][j-1] + dist[4][a2[j]];
                else
                    dp[i][j] = max (dp[i-1][j-1]+dist[a1[i]][a2[j]],dp[i][j-1]+dist[4][a2[j]], dp[i-1][j]+dist[a1[i]][4]);
            }
        }
        printf ("%d\n", dp[len1][len2]);
    }
    return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值