hdu 1080 Human Gene Functions
动态规划!!!
1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 #include<iomanip> 5 #include<cmath> 6 #include<cstring> 7 #include<vector> 8 #define ll __int64 9 #define pi acos(-1.0) 10 #define MAX 50000 11 using namespace std; 12 ll dp[202][202]; 13 int score[5][5]={ 14 5,-1,-2,-1,-3, 15 -1,5,-3,-2,-4, 16 -2,-3,5,-2,-2, 17 -1,-2,-2,5,-1, 18 -3,-4,-2,-1,-1000 19 }; 20 int swaps(char a){ 21 if (a=='A') return 0; 22 if (a=='C') return 1; 23 if (a=='G') return 2; 24 if (a=='T') return 3; 25 return 4; 26 } 27 string str1,str2; 28 int main(){ 29 int m,n,i,j,t,mmax,len1,len2,len; 30 cin>>t; 31 while (t--){ 32 cin>>len1>>str1>>len2>>str2; 33 len = max(len1,len2); 34 dp[0][0]=0; 35 for (i=1;i<=len1;i++){ 36 dp[i][0] = dp[i-1][0] + score[swaps(str1[i-1])][4]; 37 } 38 for (i=1;i<=len2;i++){ 39 dp[0][i] = dp[0][i-1] + score[4][swaps(str2[i-1])]; 40 } 41 for (i=1;i<=len1;i++) 42 for (j=1;j<=len2;j++){ 43 dp[i][j] = dp[i][j-1] + score[4][swaps(str2[j-1])]; 44 if (dp[i][j] < dp[i-1][j]+score[swaps(str1[i-1])][4]) 45 dp[i][j] = dp[i-1][j]+score[swaps(str1[i-1])][4]; 46 if (dp[i][j] < dp[i-1][j-1]+score[swaps(str1[i-1])][swaps(str2[j-1])]) 47 dp[i][j] = dp[i-1][j-1]+score[swaps(str1[i-1])][swaps(str2[j-1])]; 48 } 49 cout<<dp[len1][len2]<<endl; 50 } 51 return 0; 52 }