POJ1080 ZOJ1027 Human Gene Functions

//4_7_15:	Human Gene Functions 基因序列匹配 POJ1080 ZOJ1027
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int score[5][5] = {{-1000,-3,-4,-2,-1},{-3,5,-1,-2,-1},
{-4,-1,5,-3,-2},{-2,-2,-3,5,-2},{-1,-1,-2,-2,5}};
int max(int a,int b,int c)
{
	int temp = a > b ? a : b;
	return temp > c ? temp : c;
}
int main()
{
	int i,j,T,a,b,c,len1,len2,s1[105],s2[105],f[105][105];
	char str1[105],str2[105];
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%s",&len1,str1);
		scanf("%d%s",&len2,str2);
		memset(f,0,sizeof(f));
		for(i = 0;i < len1;i ++)
		{
			if(str1[i] == 'A')		s1[i] = 1;
			else if(str1[i] == 'C') s1[i] = 2;
			else if(str1[i] == 'G')	s1[i] = 3;
			else					s1[i] = 4;
		}
		s1[len1++] = 0;
		for(i = 0;i < len2;i ++)
		{
			if(str2[i] == 'A')		s2[i] = 1;
			else if(str2[i] == 'C') s2[i] = 2;
			else if(str2[i] == 'G')	s2[i] = 3;
			else					s2[i] = 4;
		}
		s2[len2++] = 0;
		for(i = 1;i <= len1;i ++)	f[i][0] = f[i - 1][0] + score[0][s1[i - 1]];
		for(j = 1;j <= len2;j ++)	f[0][j] = f[0][j - 1] + score[0][s2[j - 1]];
		for(i = 1;i <= len1;i ++)
			for(j = 1;j <= len2;j ++)
			{
				a = f[i - 1][j] + score[0][s1[i - 1]];
				b = f[i][j - 1] + score[0][s2[j - 1]];
				c = f[i - 1][j - 1] + score[s1[i - 1]][s2[j - 1]];
				f[i][j] = max(a,b,c);
			}
		printf("%d\n",max(f[len1 - 1][len2],f[len1][len2 - 1],f[len1 - 1][len2 - 1]));
	}
	return 0;
}
/*测试结果:通过POJ1080 ZOJ1027检测
2
7 AGTGATG
5 GTTAG
14
7 AGCTATT
9 AGCTTTAAA
21
请按任意键继续. . .
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值