hdu 1080

Human Gene Functions

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2411    Accepted Submission(s): 1365

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

Asia 2001, Taejon (South Korea)

#include <iostream>
#include <algorithm>
using namespace std;
#define inf 0x3fffffff
#define M 105

int dp[M][M], v[20][20] = {0};
char a[M], b[M]; 

int main()
{
    v[0][0] = v[2][2] = v[6][6] = v[19][19] = 5;
    v[0][2] = v[2][0] = -1;
    v[0][6] = v[6][0] = -2;
    v[0][19] = v[19][0] = -1;
    v[2][6] = v[6][2] = -3;
    v[2][19] = v[19][2] = -2;
    v[6][19] = v[19][6] = -2;
    v[7][0] = -3;	//7表示‘-‘,0,2,6,19分别表示A,C,G,T
    v[7][2] = -4;
    v[7][6] = -2;
    v[7][19] = -1;
    int i, j, la, lb, t;
    scanf ("%d", &t);
    while (t--)
    {
        scanf ("%d%s%d%s", &la, a, &lb, b);
        for (i = 0; i <= la; i++)
            for (j = 0; j <= lb; j++)
                dp[i][j] = -inf;
        dp[0][0] = 0;
        for (i = 1; i <= la; i++)	//一系列的边界初始化
            dp[i][0] = dp[i-1][0] + v[7][a[i-1]-‘A‘];
        for (j = 1; j <= lb; j++)
            dp[0][j] = dp[0][j-1] + v[7][b[j-1]-‘A‘];
        for (i = 1; i <= la; i++)
        {
            for (j = 1; j <= lb; j++)
            {
//状态转移方程
                dp[i][j] = max (dp[i][j],
                        max (dp[i-1][j-1]+v[a[i-1]-‘A‘][b[j-1]-‘A‘],
                        max (dp[i][j-1]+v[7][b[j-1]-‘A‘],
                        dp[i-1][j]+v[7][a[i-1]-‘A‘])));
            }
        }
        printf ("%d\n", dp[la][lb]);
    }
    return 0;
}

  

时间: 2024-10-06 00:43:02

hdu 1080的相关文章

HDU 1080 Human Gene Functions

最长公共子序列的变形 题目大意:给出两个基因序列,求这两个序列的最大相似度. 题目中的表格给出了两两脱氧核苷酸的相似度. 状态转移方程为: dp[i][j] = max(dp[i-1][j]+Similarity(s1[i], '-'),                     dp[i][j-1]+Similarity(s2[j], '-'),                     dp[i-1][j-1]+Similarity(s1[i], s2[j])); 注意边界的初始化. 1 //#

hdu 1080(LCS变形)

Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3008    Accepted Submission(s): 1701 Problem Description It is well known that a human gene can be considered as a sequence,

HDU 1080 DP

匹配两个人相似度.A,G,C,T,每两个都会有一个对应的值,给出两串基因,长度可以不一样,可以在基因中间加_使两串长度一样,然后有一个对应值,求最大对应值. 先做出对应的表 DP方程: x=dp[i-1][j-1]+hash[str_a[i-1]][str_b[j-1]]; y=dp[i-1][j]+hash[str_a[i-1]]['-']; z=dp[i][j-1]+hash[str_b[j-1]]['-']; p[i][j]=Max(x,y,z); #include "stdio.h&qu

HDU 1080 Human Gene Functions--DP--(变形最长公共子)

意甲冠军:该基因序列的两端相匹配,四种不同的核苷酸TCGA有不同的分值匹配.例如T-G比分是-2,它也可以被加入到空格,空洞格并且还具有一个相应的核苷酸匹配分值,求最大比分 分析: 在空气中的困难格的数量和位置不确定 二维dp,dp[i][j]表示序列a的前i段和序列b的前j段匹配时的最大分数. 接下来细致分析当i和j匹配的情况:1.a[i]与b[j]匹配:2.a[i]与b[j-1].3.a[i]与b[j+1]. 所以方程:dp [i][j]=  max(dp[i-1][j]+mat[i]['#

hdu 1080 Human Gene Functions(DP)

题意: 人类基因由A.C.G.T组成. 有一张5*5的基因表.每格有一个值,叫相似度.例:A-C:-3.意思是如果A和C配对, 则它俩的相似度是-3[P.S.:-和-没有相似度,即-和-不能配对] 现在给两条基因片段.(长度不一定相等) 现在你要在两条基因片段中插入若干个-(空白基因),使得两个基因片段长度相等,且得到的整体相似度的值最大.[再次P.S.:-和-不能配对] 思路: 因为-和-不能匹配,所以插入的-的个数是有限的. str1的第一个基因可以与str1的第一个或-配对.然后,,,,很

hdu 1080 Human Gene Functions (动态规划)

Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2402    Accepted Submission(s): 1360 Problem Description It is well known that a human gene can be considered as a sequence,

HDU 1080 Human Gene Functions--DP--(真是醉了)

题意:两端基因序列匹配,四种不同的核苷酸TCGA匹配时有不同的分数,如T-G的分数是-2,还可以添加空格,空格与核苷酸匹配也有相应的分数,求最大的分数 分析: 难点在空格的数量和位置不确定 二维dp,dp[i][j]表示序列a的前i段和序列b的前j段匹配时的最大分数.接下来仔细分析当i和j匹配的情况:1.a[i]与b[j]匹配:2.a[i]与b[j-1]:3.a[i]与b[j+1]. 所以方程:dp [i][j]=  max(dp[i-1][j]+mat[i]['#'],dp[i][j-1]+m

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

HDU 1058 Humble Numbers(离线打表)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有5842. 1 #include<stdio.h> 2 #define INT __int64 3 INT ans[5850] = { 4 0,1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,4