HDU 1080 Human Gene Functions

来源:互联网 发布:炫踪网络 ceo 编辑:程序博客网 时间:2024/05/16 14:01

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


做了半天没做出来。 又去读了遍题。 看到了 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 123456789int 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