Dang_Quan_10_Tin

Untitled

Mar 4th, 2021
740
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #define task "BGAME"
  5. using namespace std;
  6. using ll = long long;
  7. using ld = long double;
  8.  
  9. const int N = 1e5 + 2;
  10. int n, r, c[6];
  11. ll t, d, e;
  12. ll dp[2][21][21][21][21][21], val[505][6];
  13.  
  14. void Read()
  15. {
  16.     cin >> n >> t >> r >> d >> e;
  17.     for (int i = 1; i <= n; ++i)
  18.         cin >> c[i];
  19.     for (int i = 1; i <= r; ++i)
  20.         for (int j = 1; j <= n; ++j)
  21.             cin >> val[i][j];
  22. }
  23.  
  24. inline void Maximize(ll &x, ll y)
  25. {
  26.     if (x < y)
  27.         x = y;
  28. }
  29.  
  30. #define f(x, y, z, t, k, h) dp[(x)&1][y][z][t][k][h]
  31.  
  32. void Solve()
  33. {
  34.     memset(dp, -1, sizeof dp);
  35.     f(0, 0, 0, 0, 0, 0) = t;
  36.     for (int i = 0; i < n; ++i)
  37.     {
  38.         for (int j1 = 0; j1 <= c[1]; ++j1)
  39.             for (int j2 = 0; j2 <= c[2]; ++j2)
  40.                 for (int j3 = 0; j3 <= c[3]; ++j3)
  41.                     for (int j4 = 0; j4 <= c[4]; ++j4)
  42.                         for (int j5 = 0; j5 <= c[5]; ++j5)
  43.                             if (f(i, j1, j2, j3, j4, j5) >= 0)
  44.                                 for (int t1 = 0; t1 <= c[1]; ++t1)
  45.                                     for (int t2 = 0; t2 <= c[2]; ++t2)
  46.                                         for (int t3 = 0; t3 <= c[3]; ++t3)
  47.                                             for (int t4 = 0; t4 <= c[4]; ++t4)
  48.                                                 for (int t5 = 0; t5 <= c[5]; ++t5)
  49.                                                 {
  50.                                                     ll cost1 = t1 > j1 ? ((j1 - t1) * (val[i + 1][1] + d)) : ((j1 - t1) * (val[i + 1][1] - e));
  51.                                                     ll cost2 = t2 > j2 ? ((j2 - t2) * (val[i + 1][2] + d)) : ((j2 - t2) * (val[i + 1][2] - e));
  52.                                                     ll cost3 = t3 > j3 ? ((j3 - t3) * (val[i + 1][3] + d)) : ((j3 - t3) * (val[i + 1][3] - e));
  53.                                                     ll cost4 = t4 > j4 ? ((j4 - t4) * (val[i + 1][4] + d)) : ((j4 - t4) * (val[i + 1][4] - e));
  54.                                                     ll cost5 = t5 > j5 ? ((j5 - t5) * (val[i + 1][5] + d)) : ((j5 - t5) * (val[i + 1][5] - e));
  55.                                                     Maximize(f(i + 1, t1, t2, t3, t4, t5), f(i, j1, j2, j3, j4, j5) + cost1 + cost2 + cost3 + cost4 + cost5);
  56.                                                 }
  57.         memset(dp[i & 1], -1, sizeof dp[i & 1]);
  58.     }
  59.     cout << f(n, 0, 0, 0, 0, 0);
  60. }
  61.  
  62. int32_t main()
  63. {
  64.     ios_base::sync_with_stdio(0);
  65.     cin.tie(0);
  66.     cout.tie(0);
  67.     if (fopen(task ".INP", "r"))
  68.     {
  69.         freopen(task ".INP", "r", stdin);
  70.         freopen(task ".OUT", "w", stdout);
  71.     }
  72.     Read();
  73.     Solve();
  74. }
  75.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×