ZOJ 1027

最长公共子序列 变形

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <cmath>
#include <vector>
#define INF 0x3f
#define eps 1e-6
#define moo 1000000007
using namespace std;
#define maxn 140
char str1[maxn];
char str2[maxn];
int len1,len2;
int dp[110][110];
int score[][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}
    };
map<char,int>map_;
void init()
{
    map_['A']=0;
    map_['C']=1;
    map_['G']=2;
    map_['T']=3;
    map_['-']=4;
}
int main()
{

    int T;
    cin>>T;
    init();
    while(T--)
    {

        scanf("%d%s",&len1,str1+1);
        scanf("%d%s",&len2,str2+1);
        dp[0][0]=0;
        for(int i=1;i<=len1;i++)
            dp[i][0]=dp[i-1][0]+score[map_[str1[i]]][4] ;
        for(int i=1;i<=len2;i++)
            dp[0][i]=dp[0][i-1]+score[4][map_[str2[i]]];

        for(int i=1;i<=len1;i++)
        for(int j=1;j<=len2;j++)
        {
            dp[i][j]=dp[i-1][j-1]+score[map_[str1[i]]][ map_[str2[j]] ];
            dp[i][j]=max(dp[i][j],dp[i-1][j]+score[map_[str1[i]]][4]);
            dp[i][j]=max(dp[i][j],dp[i][j-1]+score[4][map_[str2[j]]]);
        }

      cout<<dp[len1][len2]<<endl;
    }
}


posted on 2016-07-12 10:45  胖胖的乓乓  阅读(129)  评论(0编辑  收藏  举报

导航