Advertisement
Dmaxiya

蓝桥杯真题 - 食堂 35% 代码

Mar 6th, 2025
151
0
364 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 100 + 100;
  6. int q, a2, a3, a4, b4, b6, ans;
  7. set<vector<int>> dp[maxn][maxn];
  8. set<vector<int>>::iterator it;
  9. vector<vector<int>> four = {
  10.     {1, 0, 0},
  11.     {0, 1, 0},
  12.     {0, 0, 1},
  13.     {2, 0, 0}
  14. };
  15. vector<vector<int>> six = {
  16.     {0, 0, 1},
  17.     {0, 1, 0},
  18.     {0, 2, 0},
  19.     {1, 0, 0},
  20.     {1, 0, 1},
  21.     {1, 1, 0},
  22.     {2, 0, 0},
  23.     {3, 0, 0}
  24. };
  25.  
  26. void solve(int prei, int prej, int nowi, int nowj, vector<vector<int>> &vct) {
  27.     for (it = dp[prei][prej].begin(); it != dp[prei][prej].end(); ++it) {
  28.         for (vector<int> &v : vct) {
  29.             bool flag = true;
  30.             for (int i = 0; i < 3; ++i) {
  31.                 if (v[i] > (*it)[i]) {
  32.                     flag = false;
  33.                     break;
  34.                 }
  35.             }
  36.             if (flag) {
  37.                 dp[nowi][nowj].insert({(*it)[0] - v[0], (*it)[1] - v[1], (*it)[2] - v[2]});
  38.             }
  39.         }
  40.     }
  41. }
  42.  
  43. int cal(const vector<int> &vct) {
  44.     return (a2 - vct[0]) * 2 + (a3 - vct[1]) * 3 + (a4 - vct[2]) * 4;
  45. }
  46.  
  47. int main() {
  48. #ifdef ExRoc
  49.     freopen("test.txt", "r", stdin);
  50. #endif // ExRoc
  51.     ios::sync_with_stdio(false);
  52.  
  53.     cin >> q;
  54.     while (q--) {
  55.         cin >> a2 >> a3 >> a4 >> b4 >> b6;
  56.         for (int i = 0; i <= b4; ++i) {
  57.             for (int j = 0; j <= b6; ++j) {
  58.                 dp[i][j].clear();
  59.                 if (i == 0 && j == 0) {
  60.                     dp[i][j].insert({a2, a3, a4});
  61.                     continue;
  62.                 }
  63.                 if (i != 0) {
  64.                     solve(i - 1, j, i, j, four);
  65.                 }
  66.                 if (j != 0) {
  67.                     solve(i, j - 1, i, j, six);
  68.                 }
  69.             }
  70.         }
  71.         ans = 0;
  72.         for (it = dp[b4][b6].begin(); it != dp[b4][b6].end(); ++it) {
  73.             ans = max(ans, cal(*it));
  74.         }
  75.         cout << ans << endl;
  76.     }
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement