DuongNhi99

C - Human Gene Functions (1-12)

Nov 30th, 2020 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7. int score[5][5] = { 5, -1, -2, -1, -3,
  8.                     -1, 5, -3, -2, -4,
  9.                     -2, -3, 5, -2, -2,
  10.                     -1, -2, -2, 5, -1,
  11.                     -3, -4, -2, -1, 0
  12.                   };
  13.  
  14. int change(char c) {
  15.     if(c == 'A') return 0;
  16.     if(c == 'C') return 1;
  17.     if(c == 'G') return 2;
  18.     if(c == 'T') return 3;
  19.     if(c == ' ') return 4;
  20. }
  21.  
  22. int dp[105][105];
  23.  
  24. void solve() {
  25.     int n, m;
  26.     string s, t;
  27.  
  28.     cin >> n >> s;
  29.     cin >> m >> t;
  30.  
  31.     memset(dp, 0, sizeof(dp));
  32.  
  33.     for(int i = 1; i <= n; i++)
  34.         dp[i][0] = dp[i-1][0] + score[change(s[i-1])][change(' ')];
  35.  
  36.     for(int j = 1; j <= m; j++)
  37.         dp[0][j] = dp[0][j-1] + score[change(' ')][change(t[j-1])];
  38.  
  39.     for(int i = 1; i <= n; i++)
  40.         for(int j = 1; j <= m; j++) {
  41.             dp[i][j] = -1e9;
  42.             dp[i][j] = max(dp[i][j], dp[i-1][j-1] + score[change(s[i-1])][change(t[j-1])]);
  43.             dp[i][j] = max(dp[i][j], dp[i-1][j] + score[change(s[i-1])][change(' ')]);
  44.             dp[i][j] = max(dp[i][j], dp[i][j-1] + score[change(t[j-1])][change(' ')]);
  45.         }
  46.  
  47.     cout << dp[n][m] << '\n';
  48. }
  49.  
  50. int main() {
  51.     //freopen("C-HumanGeneFunctions.inp", "r", stdin);
  52.     //freopen("C-HumanGeneFunctions.out", "w", stdout);
  53.     ios_base::sync_with_stdio(false);
  54.     cin.tie(NULL); cout.tie(NULL);
  55.  
  56.     int t; cin >> t;
  57.     while(t--) {
  58.         solve();
  59.     }
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment