Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一道用dp 做的题,有兴趣的来看看!

Posted by wangbaobao at 2009-05-01 13:57:45 on Problem 1080
#include"iostream"
using namespace std;
#define Max_size  101
int f[Max_size][Max_size];
int max(int x,int y)
{
	return x>=y? x:y;
}
int Max(int x,int y,int z)
{
	return max(max(x,y),z);
}
int int1(char x)
{
	if(x=='A')
		return 0;
	if(x=='C')
		return 1;
	if(x=='G')
		return 2;
	if(x=='T')
		return 3;
	if(x=='-')
		return 4;
}
int value(char a,char b)
{
	
	char  value_list[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}
	};
   return value_list[int1(a)][int1(b)];

}
int main()
{
	int Test_case;
	cin>>Test_case;
	while(Test_case--)
	{
		int len1,len2;
		char str1[101],str2[101];
		memset(f,0,sizeof(f));
		cin>>len1>>str1;
		cin>>len2>>str2;
		for(int i=0;i<=len1;i++)
			for(int j=0;j<=len2;j++)
			{

		       if(i==0&&j==0)
				   f[i][j]=0;
			   else if(j==0)
			   {
				   f[i][j]=f[i-1][j]+value(str1[i-1],'-');
			   }
			   else if(i==0)
			   {
				   f[i][j]=f[i][j-1]+value('-',str2[j-1]);
			   }
			   else
			   {
				   f[i][j]=Max((f[i-1][j-1]+value(str1[i-1],str2[j-1])),(f[i-1][j]+value(str1[i-1],'-')),
					   (f[i][j-1]+value('-',str2[j-1])));
			   }
			}
			cout<<f[len1][len2]<<endl;
	}
	return 1;
}
    

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator