Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <cstring>
- using namespace std;
- int n;
- int a[1000], b[1000], dp[1000][1000];
- map<char, int> m = {
- {'1', 1},
- {'2', 2},
- {'3', 3},
- {'4', 4},
- {'5', 5},
- {'6', 6},
- {'7', 7},
- {'8', 8},
- {'9', 9},
- {'A', 20},
- {'R', 21},
- {'Q', 15},
- {'T', 10},
- {'J', 15}};
- char t;
- int v(int i, int j)
- {
- if (i == 21 && j == 21)
- return 100;
- if (i == 21)
- return 2 * j;
- if (j == 21)
- return 2 * i;
- return i + j;
- }
- int d(int i, int j)
- {
- if (i == n)
- return 0;
- if (j == n)
- return 0;
- if (dp[i][j] != -1)
- return dp[i][j];
- int mx = -99999;
- if (a[i] == b[j] || a[i] == 21 || b[j] == 21)
- mx = d(i + 1, j + 1) + v(a[i], b[j]);
- mx = max(d(i + 1, j + 1), mx);
- mx = max(d(i + 1, j), mx);
- mx = max(d(i, j + 1), mx);
- return dp[i][j] = mx;
- }
- int main()
- {
- while (cin >> n, n)
- {
- for (int i = 0; i < n; ++i)
- cin >> t, a[i] = m[t];
- for (int i = 0; i < n; ++i)
- cin >> t, b[i] = m[t];
- memset(dp, -1, sizeof dp);
- cout << d(0, 0) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement