hdu 1080 Human Gene Functions(DP)

题意:

人类基因由A、C、G、T组成。

有一张5*5的基因表。每格有一个值,叫相似度。例:A-C:-3。意思是如果A和C配对, 则它俩的相似度是-3【P.S.:-和-没有相似度,即-和-不能配对】

现在给两条基因片段。(长度不一定相等)

现在你要在两条基因片段中插入若干个-(空白基因),使得两个基因片段长度相等,且得到的整体相似度的值最大。【再次P.S.:-和-不能配对】

思路:

因为-和-不能匹配,所以插入的-的个数是有限的。

str1的第一个基因可以与str1的第一个或-配对。然后,,,,很快就看到了DP结构,,,

和最长公共子串一样滴的意思,,,

DP方程:dp[i][j]:str1的前i个和str2的前j个能获得的最大相似度值。

看代码,,

代码:

int l1,l2;
char s1[105], s2[105];
int S1[105], S2[105];
int a[6][6]={{5,-1,-2,-1,-3},{-1,5,-3,-2,-4},{-2,-3,5,-2,-2},{-1,-2,-2,5,-1},{-3,-4,-2,-1,inf}};
int dp[105][105];

int maxx(int a,int b,int c){
    int t=max(a,b);
    return max(t,c);
}

int main(){

    int T;
    cin>>T;
    while(T--){
        scanf("%d",&l1);
        scanf("%s",s1);
        scanf("%d",&l2);
        scanf("%s",s2);
        rep(i,0,l1-1){
            if(s1[i]==‘A‘) S1[i]=0;
            else if(s1[i]==‘C‘) S1[i]=1;
            else if(s1[i]==‘G‘) S1[i]=2;
            else S1[i]=3;
        }
        rep(i,0,l2-1){
            if(s2[i]==‘A‘) S2[i]=0;
            else if(s2[i]==‘C‘) S2[i]=1;
            else if(s2[i]==‘G‘) S2[i]=2;
            else S2[i]=3;
        }

        dp[0][0]=0;
        rep(i,0,l2-1){
            dp[0][i+1]=dp[0][i]+a[4][S2[i]];
        }
        rep(i,0,l1-1){
            dp[i+1][0]=dp[i][0]+a[S1[i]][4];
        }
        rep(i,1,l1){
            rep(j,1,l2){
                dp[i][j]=maxx( dp[i-1][j-1]+a[S1[i-1]][S2[j-1]],dp[i-1][j]+a[S1[i-1]][4],dp[i][j-1]+a[4][S2[j-1]] );
            }
        }
        printf("%d\n",dp[l1][l2]);
    }

    return 0;
}
时间: 2024-08-05 11:14:02

hdu 1080 Human Gene Functions(DP)的相关文章

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,

poj 1080 Human Gene Functions (dp,LCS)

链接:poj 1080 题意:给定两个字符串,求它们对齐匹配的最大值 要求:可以两个字符匹配,也可以一个字符和'-'匹配, 但是不能两个'-'匹配,例如: AGTGATG GTTAG 这两个字符串可以看成是 AGTGATG -GTTA-G 也可以看成是 AGTGAT-G -GT--TAG 分析:这是一个变形的最长公共子序列,最优解: 1.取字符i-1和j-1的时候dp[i][j]=dp[i-1][j-1]+a[s1[i-1]][s2[j-1]]; 2.取字符i-1,不取j-1的时候dp[i][j

POJ 1080 Human Gene Functions(LCS)

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

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 //#

poj 1080 Human Gene Functions(lcs,较难)

Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19573   Accepted: 10919 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

POJ 1080-Human Gene Functions(DP)

Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17300   Accepted: 9617 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

POJ 1080 Human Gene Functions 【dp】

题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经典题,很容易想到状态dp[i][j],指第一个长度为i的串和第二个长度为j的串配对的最大分数.显然,这个状态可以由dp[i][j-1],dp[i-1][j],dp[i-1][j-1]三个子问题得到,即第一串最后一个字符对应空格.第二串最后一个字符对应空格和第一串第二串最后一个字符配对所得到的分数这三

UVALive 2324 Human Gene Functions(动态规划)

题意:求出将两个字符串改成一样长度所能形成最大的相似度. 思路:这个可以说是编辑距离的一个变形,编辑距离最终状态时要两个字符串完全一致,这个就是要求长度一样,而且这个只允许插入“—”这一个字符.模仿编辑距离定义状态,dp[i][j]表示将第一个字符串的前i个字符与第二个字符串的前j个字符变为相同长度所能形成的最大相似度.设两个字母的相似度为g[i][j]; 那状态转移为 dp[i][j] = max( dp[i][j-1] + g[j][5], d[i-1][j] + g[i][5],dp[i-

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