Hoj 1316 Human Gene Functions

题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=1316

注意此DP方程:

设两基因串为an,bm

a[i],b[j]分别表示a串的第i个核苷

b串的第j个核苷

ax,by为an,bm的子串;

c[x][y]表示子串ax,by间最大相似程度值

则c[n][m]表示串an,bm间最大相似程度值

value(x,y)表示核苷x核苷y的相似程度值

'-'表示核苷为空

则有如下的状态转移方程:

1.c[i][j]=max(c[i-1][j-1]+value(a[i],b[j]),c[i][j-1]+value('-',b[j]),c[i-1][j]+value(a[i],'-'))

if i,j>0

2.c[i][0] = c[i-1][0] + value[i]['-']

3.c[0][i] = c[0][i-1] + value['-'][i]

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;

char temp[1000];
char a[1000];
char b[1000];

int c[1000][1000];


int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int t;
    int la,lb;
    scanf("%d",&t);
    int value[6][6] = {0,0,0,0,0,0,
                       0,5,-1,-2,-1,-3,
                       0,-1,5,-3,-2,-4,
                       0,-2,-3,5,-2,-2,
                       0,-1,-2,-2,5,-1,
                       0,-3,-4,-2,-1,0
                        };

    while(t--)
    {
        scanf(" %d %s",&la,temp);
        for(int i=0;i<la;i++)
        {
            if(temp[i] == 'A')
            {
                a[i] = 1;
            }
            else if(temp[i] == 'C')
            {
                a[i] = 2;
            }
            else if(temp[i] == 'G')
            {
                a[i] = 3;
            }
            else if(temp[i] == 'T')
            {
                a[i] = 4;
            }
        }
        scanf(" %d %s",&lb,temp);
        for(int i=0;i<lb;i++)
        {
            if(temp[i] == 'A')
            {
                b[i] = 1;
            }
            else if(temp[i] == 'C')
            {
                b[i] = 2;
            }
            else if(temp[i] == 'G')
            {
                b[i] = 3;
            }
            else if(temp[i] == 'T')
            {
                b[i] = 4;
            }
        }
        memset(c,0,sizeof(c));

        for(int i=1;i<=lb;i++)
        {
            c[0][i] = c[0][i-1] + value[5][b[i-1]];
        }
        for(int i=1;i<=la;i++)
        {
            c[i][0] = c[i-1][0] + value[a[i-1]][5];
        }

        for(int i=1;i<=la;i++)
        {
            for(int j=1;j<=lb;j++)
            {
                c[i][j] = max(c[i-1][j-1] + value[a[i-1]][b[j-1]],max(c[i][j-1] + value[5][b[j-1]],c[i-1][j] + value[a[i-1]][5]));
            }
        }
        printf("%d\n",c[la][lb]);
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值