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

LCS的变形

Posted by zpdlut at 2010-09-07 09:48:21 on Problem 1080
#include<iostream>
#define MAX 105
using namespace std;
int set1[MAX];
int set2[MAX];
int map[MAX][MAX];
int getMax(int a,int b)
{
	return a>b?a:b;
}
int table[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,-127}
};
int convert(char ch)
{
	
	switch(ch)
	{
	case 'A':return 0;
	case 'C':return 1;
	case 'G':return 2;
	case 'T':return 3;


	}
}
int main()
{
	int nums;
	cin>>nums;
	char ch;
	for(int i=1;i<=nums;i++)
	{
		int num1,num2;
		cin>>num1;
		for(int j=1;j<=num1;j++)
		{
			cin>>ch;
			set1[j]=convert(ch);
		}
		cin>>num2;
		for(int j=1;j<=num2;j++)
		{
			cin>>ch;
			set2[j]=convert(ch);
		}
		map[0][0] = 0;
		for(int j=1;j<=num2;j++)
				map[0][j]=map[0][j-1]+table[4][set2[j]];
		for(int j=1;j<=num1;j++)
				map[j][0]=map[j-1][0]+table[set1[j]][4];
		for(int i=1;i<=num1;i++)
		{
			for(int j=1;j<=num2;j++)
			{
				if(set1[i]==set2[j])
					map[i][j] = map[i-1][j-1]+5;
				else
				{
					int max = 0;
					int temp=getMax(map[i-1][j-1]+table[set1[i]][set2[j]],map[i-1][j]+table[set1[i]][4]);
					map[i][j]=getMax(temp,map[i][j-1]+table[4][set2[j]]);
				}
			}
		}
		cout<<map[num1][num2]<<endl;
	}
	return 0;
}

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