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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| #include<cstdio> #include<cstring> #include<iostream> #define MAX_INT 2147483647 #define MAXN 105
using namespace std;
int Map[5][5] = { {0,-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 seq1[MAXN],seq2[MAXN],Max,n1,n2;
int ref(char c) { switch (c) { case 'A': return 1; case 'C': return 2; case 'G': return 3; case 'T': return 4; } }
void dfs(int id1,int id2,int sum) { if(id2 <= n2 + 1) { if(id2 == n2 + 1) { for(int i = id1;i <= n1;i ++) sum += Map[seq1[i]][0]; Max = max(Max,sum); return ; } int limi = n1 - n2 + id2,tsum = sum; for(int i = id1;i <= limi;i ++) { if(i > id1) tsum += Map[seq1[i-1]][0]; dfs(i + 1 , id2 + 1 , tsum + Map[seq1[i]][seq2[id2]]); } } }
int main() { freopen("./1080.in" , "r" , stdin); int T,i,j; char c; cin>>T; while(T --) { scanf("%d%c",&n1,&c); for(i = 1;i <= n1;i ++) { scanf("%c",&c); seq1[i] = ref(c); } scanf("%d%c",&n2,&c); for(i = 1;i <= n2;i ++) { scanf("%c",&c); seq2[i] = ref(c); } if(n1 < n2) { for(int i = 1;i <= n1;i ++) swap(seq1[i] , seq2[i]); for(int i = n1 + 1;i <= n2;i ++) seq1[i] = seq2[i]; swap(n1 , n2); } Max = -MAX_INT; dfs(1,1,0); cout<<Max<<endl; } return 0; }
|