SHARE
TWEET

Untitled

a guest Oct 15th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <map>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int n;
  7. int a[1000], b[1000], dp[1000][1000];
  8. map<char, int> m = {
  9.     {'1', 1},
  10.     {'2', 2},
  11.     {'3', 3},
  12.     {'4', 4},
  13.     {'5', 5},
  14.     {'6', 6},
  15.     {'7', 7},
  16.     {'8', 8},
  17.     {'9', 9},
  18.     {'A', 20},
  19.     {'R', 21},
  20.     {'Q', 15},
  21.     {'T', 10},
  22.     {'J', 15}};
  23. char t;
  24.  
  25. int v(int i, int j)
  26. {
  27.     if (i == 21 && j == 21)
  28.         return 100;
  29.     if (i == 21)
  30.         return 2 * j;
  31.     if (j == 21)
  32.         return 2 * i;
  33.     return i + j;
  34. }
  35.  
  36. int d(int i, int j)
  37. {
  38.     if (i == n)
  39.         return 0;
  40.     if (j == n)
  41.         return 0;
  42.     if (dp[i][j] != -1)
  43.         return dp[i][j];
  44.     int mx = -99999;
  45.     if (a[i] == b[j] || a[i] == 21 || b[j] == 21)
  46.         mx = d(i + 1, j + 1) + v(a[i], b[j]);
  47.     mx = max(d(i + 1, j + 1), mx);
  48.     mx = max(d(i + 1, j), mx);
  49.     mx = max(d(i, j + 1), mx);
  50.     return dp[i][j] = mx;
  51. }
  52.  
  53. int main()
  54. {
  55.     while (cin >> n, n)
  56.     {
  57.         for (int i = 0; i < n; ++i)
  58.             cin >> t, a[i] = m[t];
  59.         for (int i = 0; i < n; ++i)
  60.             cin >> t, b[i] = m[t];
  61.         memset(dp, -1, sizeof dp);
  62.         cout << d(0, 0) << endl;
  63.     }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top