HDU 1080 Human Gene Functions

读完这个题 一直以为添加空格 使得两个字符串一样长。 然后求最大相似度。。


做了半天没做出来。 又去读了遍题。 看到了 if necessary, in appropriate positions of the genes to make them equally long 


然后醉了。。  知道之后就比较好做了。  d【i】【j】 代表 第一个字符串用了 i个字符,第二个字符串用了 j个字符 之后的相似度


比较简单了。 因为对于某一个字符 要不和空格匹配 要不和 字符匹配。 取一个最大值就好了。


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 100+10
#define INF (1<<30)
#define mod 123456789
int cal(char c){
    if(c == 'A') return 0;
    if(c == 'C') return 1;
    if(c == 'G') return 2;
    if(c == 'T') return 3;
    if(c == ' ') return 4;
}
int math[MAXN][MAXN] = {{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 main (){
    int t;
    scanf("%d",&t);
    while(t--){
        int len1,len2;
        char s1[MAXN],s2[MAXN];
        scanf("%d%s",&len1,s1+1);
        scanf("%d%s",&len2,s2+1);
        int d[MAXN][MAXN] = {0};
        for(int i = 0; i <= len1; i++){
            for(int j = 0; j <= len2; j++){
                if(i == 0 && j == 0)
                    continue;
                if(i == 0)
                    d[i][j] = d[i][j-1] + math[4][cal(s2[j])];
                else if(j == 0)
                    d[i][j] = d[i-1][j] + math[cal(s1[i])][4];
                else
                    d[i][j] = max(d[i-1][j]+math[cal(s1[i])][4], max(d[i][j-1]+math[4][cal(s2[j])], d[i-1][j-1]+math[cal(s1[i])][cal(s2[j])]));
                //printf("%d %d %d\n",i,j,d[i][j]);
            }
        }
        printf("%d\n",d[len1][len2]);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值