Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  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. char g[1000], h[1000];
  9. map<char, int> m = {
  10. {'1', 1},
  11. {'2', 2},
  12. {'3', 3},
  13. {'4', 4},
  14. {'5', 5},
  15. {'6', 6},
  16. {'7', 7},
  17. {'8', 8},
  18. {'9', 9},
  19. {'A', 20},
  20. {'R', 21},
  21. {'Q', 15},
  22. {'T', 10},
  23. {'J', 15},
  24. {'K', 15}};
  25. char t;
  26.  
  27. int v(int i, int j)
  28. {
  29. if (i == 21 && j == 21)
  30. return 100;
  31. if (i == 21)
  32. return 2 * j;
  33. if (j == 21)
  34. return 2 * i;
  35. return i + j;
  36. }
  37.  
  38. int d(int i, int j)
  39. {
  40. if (i == n)
  41. return 0;
  42. if (j == n)
  43. return 0;
  44. if (dp[i][j] != -1)
  45. return dp[i][j];
  46. int mx = -99999;
  47. if (g[i] == h[j] || a[i] == 21 || b[j] == 21)
  48. mx = d(i + 1, j + 1) + v(a[i], b[j]);
  49. mx = max(d(i + 1, j + 1), mx);
  50. mx = max(d(i + 1, j), mx);
  51. mx = max(d(i, j + 1), mx);
  52. return dp[i][j] = mx;
  53. }
  54.  
  55. int main()
  56. {
  57. cout << v(m['K'], m['K']) << endl;
  58. while (cin >> n, n)
  59. {
  60. for (int i = 0; i < n; ++i)
  61. cin >> g[i], a[i] = m[g[i]];
  62. for (int i = 0; i < n; ++i)
  63. cin >> h[i], b[i] = m[h[i]];
  64. memset(dp, -1, sizeof dp);
  65. cout << d(0, 0) << endl;
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement