HDU 1080 Human Gene Functions DP -

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1080

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=100+5;
const int INF=0x3f3f3f3f;
#define max3(a,b,c) max(a,max(b,c))
char s1[maxn],s2[maxn];
int d[maxn][maxn],len1,len2;
//d[i][j]表示s1前i个和s2前j个匹配的最大值
char str[]="ACGT-";
int score[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 inline Value(char a,char b){
	int p1=find(str,str+5,a)-str;
	int p2=find(str,str+5,b)-str;
	return score[p1][p2];
}
int solve()
{
	memset(d,-INF,sizeof(d));

	d[0][0]=0;
	for(int i=1;i<=len1;i++){
		d[i][0]=d[i-1][0]+Value(s1[i],'-');
		d[0][i]=d[0][i-1]+Value(s2[i],'-');
	}
	for(int i=1;i<=len1;i++)
	for(int j=1;j<=len2;j++)
		d[i][j]=max3(d[i-1][j-1]+Value(s1[i],s2[j]),d[i-1][j]+Value(s1[i],'-'),d[i][j-1]+Value(s2[j],'-'));
					//s1[i]和s2[j] 匹配           s1[i]和'-'匹配              s2[j]和'-'匹配
	
	return d[len1][len2];
}
int main(int argc, char const *argv[])
{
	int T; cin>>T;
	while(T--)
	{
		scanf("%d %s",&len1,s1+1);
		scanf("%d %s",&len2,s2+1);
		
		cout<<solve()<<endl;
	}
	return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值