Dang_Quan_10_Tin

CHƠI BẢNG

Aug 3rd, 2022 (edited)
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. constexpr int N = 1e2 + 5;
  7. constexpr ll Inf = 1e17;
  8. int n;
  9. int a[4][N], cnt[4];
  10. vector<int> b[4];
  11. ll dp[2][N][N][N];
  12.  
  13. void Read()
  14. {
  15.     cin >> n;
  16.  
  17.     for (int _ = 1; _ <= 3; ++_)
  18.     {
  19.         b[_].emplace_back(0);
  20.  
  21.         for (int i = 1; i <= n; ++i)
  22.         {
  23.             cin >> a[_][i];
  24.  
  25.             if (a[_][i] == 0)
  26.                 ++cnt[_];
  27.             else
  28.                 b[_].emplace_back(a[_][i]);
  29.         }
  30.     }
  31. }
  32.  
  33. ll Get(int id, int row, int j)
  34. {
  35.     return b[row][id - j];
  36. }
  37.  
  38. ll Cost(int id, int j1, int j2, int j3, int t1, int t2, int t3)
  39. {
  40.     if (t1 || t2 || t3)
  41.         return 0;
  42.  
  43.     return Get(id, 1, j1) * Get(id, 2, j2) * Get(id, 3, j3);
  44. }
  45.  
  46. void Maximize(ll &x, ll y)
  47. {
  48.     if (x < y)
  49.         x = y;
  50. }
  51.  
  52. void Solve()
  53. {
  54.     fill_n(&dp[0][0][0][0], 2 * N * N * N, -Inf);
  55.     dp[0][0][0][0] = 0;
  56.  
  57.     for (int i = 0; i < n; ++i)
  58.     {
  59.         int p = i & 1; // Rolling dp;
  60.  
  61.         for (int j1 = 0; j1 <= cnt[1]; ++j1)
  62.             for (int j2 = 0; j2 <= cnt[2]; ++j2)
  63.                 for (int j3 = 0; j3 <= cnt[3]; ++j3)
  64.                     if (dp[p][j1][j2][j3] != -Inf) // Neu gia tri khac -Inf moi xet tiep
  65.                     {
  66.  
  67.                         // for bo chi so t
  68.                         for (int t1 = 0; t1 < 2; ++t1)
  69.                             if (j1 + t1 <= cnt[1]) // nhanh can
  70.                                 for (int t2 = 0; t2 < 2; ++t2)
  71.                                     if (j2 + t2 <= cnt[2]) // nhanh can
  72.                                         for (int t3 = 0; t3 < 2; ++t3)
  73.                                             if (j3 + t3 <= cnt[3]) // nhanh can
  74.                                             {
  75.                                                 Maximize(dp[!p][j1 + t1][j2 + t2][j3 + t3], dp[p][j1][j2][j3] + Cost(i + 1, j1, j2, j3, t1, t2, t3));
  76.                                             }
  77.  
  78.                         dp[p][j1][j2][j3] = -Inf;
  79.                     }
  80.     }
  81.  
  82.     cout << dp[n & 1][cnt[1]][cnt[2]][cnt[3]];
  83. }
  84.  
  85. int32_t main()
  86. {
  87.     ios::sync_with_stdio(0);
  88.     cin.tie(0);
  89.     cout.tie(0);
  90.     Read();
  91.     Solve();
  92. }
Advertisement
Add Comment
Please, Sign In to add comment