Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int maxn = 100 + 100;
- int q, a2, a3, a4, b4, b6, ans;
- set<vector<int>> dp[maxn][maxn];
- set<vector<int>>::iterator it;
- vector<vector<int>> four = {
- {1, 0, 0},
- {0, 1, 0},
- {0, 0, 1},
- {2, 0, 0}
- };
- vector<vector<int>> six = {
- {0, 0, 1},
- {0, 1, 0},
- {0, 2, 0},
- {1, 0, 0},
- {1, 0, 1},
- {1, 1, 0},
- {2, 0, 0},
- {3, 0, 0}
- };
- void solve(int prei, int prej, int nowi, int nowj, vector<vector<int>> &vct) {
- for (it = dp[prei][prej].begin(); it != dp[prei][prej].end(); ++it) {
- for (vector<int> &v : vct) {
- bool flag = true;
- for (int i = 0; i < 3; ++i) {
- if (v[i] > (*it)[i]) {
- flag = false;
- break;
- }
- }
- if (flag) {
- dp[nowi][nowj].insert({(*it)[0] - v[0], (*it)[1] - v[1], (*it)[2] - v[2]});
- }
- }
- }
- }
- int cal(const vector<int> &vct) {
- return (a2 - vct[0]) * 2 + (a3 - vct[1]) * 3 + (a4 - vct[2]) * 4;
- }
- int main() {
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif // ExRoc
- ios::sync_with_stdio(false);
- cin >> q;
- while (q--) {
- cin >> a2 >> a3 >> a4 >> b4 >> b6;
- for (int i = 0; i <= b4; ++i) {
- for (int j = 0; j <= b6; ++j) {
- dp[i][j].clear();
- if (i == 0 && j == 0) {
- dp[i][j].insert({a2, a3, a4});
- continue;
- }
- if (i != 0) {
- solve(i - 1, j, i, j, four);
- }
- if (j != 0) {
- solve(i, j - 1, i, j, six);
- }
- }
- }
- ans = 0;
- for (it = dp[b4][b6].begin(); it != dp[b4][b6].end(); ++it) {
- ans = max(ans, cal(*it));
- }
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement