1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std;
int mymax(int a,int b,int c) { int temp=a>b?a:b; return temp>c?temp:c; }
int match[5][5]= { {5,-1,-2,-1,-3}, {-1,5,-3,-2,-4}, {-2,-3,5,-2,-2}, {-1,-2,-3,5,-1}, {-3,-4,-2,-1,0} };
int getnum(char ch) { switch (ch) { case 'A':return 0; case 'C':return 1; case 'G':return 2; case 'T':return 3; case '-':return 4; default:return 5; } }
int getmatch(char ch1,char ch2) { return match[getnum(ch1)][getnum(ch2)]; }
int main() { int t,len1,len2,dp[105][105],i,j; char str1[105],str2[105]; cin>>t; while(t--) { cin>>len1>>str1>>len2>>str2; dp[0][0]=0; for(i=1;i<=len1;i++) dp[i][0]=dp[i-1][0]+getmatch(str1[i-1],'-'); for(j=1;j<=len2;j++) dp[0][j]=dp[0][j-1]+getmatch(str2[j-1],'-'); for(i=1;i<=len1;i++) for(j=1;j<=len2;j++) dp[i][j]= mymax( dp[i][j-1]+getmatch(str2[j-1],'-'), dp[i-1][j]+getmatch(str1[i-1],'-'), dp[i-1][j-1]+getmatch(str1[i-1],str2[j-1]) ); cout<<dp[len1][len2]<<endl; } }
|