hdu1080 带权值的LCS

2、题目大意:
给定两个字符串a,b;其中两个字符串中的字母两两对应都有一个权值,并且两个字符串可以任意添加空格,使得有更多的字符可以对应,例如Given two genes AGTGATG and GTTAG,可以写成
AGTGAT-G
-GT–TAG 这样的最终对应权值是The score of the alignment above is (-3)+5+5+(-2)+(-3)+5+(-3)+5=9.
也可以写成
AGTGATG
-GTTA-G 这样的对应权值之和是(-3)+5+5+(-2)+5+(-1) +5=14,因为空格的加入,可以有很多种不同的权值和,要求的是最大的权值和;

#include<stdio.h>
#define max(x,y) (x>y?x:y)
int map[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,0};
int dp[110][110];
int find(char c)
{
    if(c=='A')
        return 0;
    else if(c=='C')
        return 1;
    else if(c=='G')
        return 2;
    else if(c=='T')
        return 3;
    else if(c=='-')
        return 4;
}
int maxx(int x,int y,int z)
{
    int maxn=-999999;
    if(x>maxn)
        maxn=x;
    if(y>maxn)
        maxn=y;
    if(z>maxn)
        maxn=z;
    return maxn;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        char a[110],b[110];
        int i,j,k;
        scanf("%d",&n);
        getchar(); //这里要接收前面的字符
        for(i=1;i<=n;i++)
            scanf("%c",&a[i]);
        scanf("%d",&m);
        getchar();//同上
        for(i=1;i<=m;i++)
            scanf("%c",&b[i]);
        dp[0][0]=0;
        for(i=1;i<=n;i++)
            dp[i][0]=dp[i-1][0]+map[4][find(a[i])];
        for(i=1;i<=m;i++)
            dp[0][i]=dp[0][i-1]+map[find(b[i])][4];
        for(i=1;i<=n;i++)
            for(j=1;j<=m;j++)
                dp[i][j]=maxx(dp[i-1][j-1]+map[find(a[i])][find(b[j])],dp[i-1][j]+map[find(a[i])][4],dp[i][j-1]+map[find(b[j])][4]);
        printf("%d\n",dp[n][m]);
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值