Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
LCS的变形#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator