Cho tôi xin code

Đỗ Thành Trọng 2024-09-23 3:52:28 2024-09-24 18:06:45

// PhuThuyRuntime <3
// A secret makes a woman woman

#include <bits/stdc++.h>

using namespace std;

#define eb emplace_back
#define ef emplace_front
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define fo(i, l, r) for(int i = l; i <= r; i++)
#define foi(i, l, r) for(int i = l; i >= r; i--)
#define elif else if
#define el cout << "\n";
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define fi first
#define se second
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define ll long long
#define ull unsigned long long
#define pob pop_back
#define bs binary_search
#define vi vector<int>
#define vii vector<pair<int, int>>
#define getbit(i, j) (i >> j) & 1
#define offbit(i, j) (1 << j) ^ i
#define onbit(i, j) (1 << j) | i
const int N = 1e5 + 2;
const ll mod = 1e9 + 7;
const int inf = INT_MAX;
const int base = 31;
const long double EPS = 1e-9;
const long double pi = acos(-1.0);
int n;
vi a, b, c;
vector<vi> dp[101][101];
void inp(){
     cin >> n;
     fo(i, 1, n){
          int v; cin >> v;
          if(v != 0) a.eb(v);
     }
     fo(i, 1, n){
          int v; cin >> v;
          if(v != 0) b.eb(v);
     }
     fo(i, 1, n){
          int v; cin >> v;
          if(v != 0) c.eb(v);
     }
}
int na[2], nb[2], nc[2];
int solve(){
     int ii = nb[1], jj = nc[1], kk = na[1], ss = na[0];
     if(dp[ii][jj][kk][ss] != -0x3f3f3f3f) return dp[ii][jj][kk][ss];
     if(kk + ss == 0) return 0;
     int ans = -0x3f3f3f3f;
     fo(x, 0, 1){
          fo(y, 0, 1){
               fo(z, 0, 1){
                    if(nb[x] > 0 && nc[y] > 0 && na[z] > 0){
                         nb[x]--;
                         nc[y]--;
                         na[z]--;
                         ans = max(ans, solve() + ((x + y + z == 3) ? b[ii - 1] * c[jj - 1] * a[kk - 1] : 0));
                         nb[x]++;
                         nc[y]++;
                         na[z]++;
                    }
               }
          }
     }
     return dp[ii][jj][kk][ss] = ans;
}
void sol(){
     na[1] = (int)a.size(); na[0] = n - na[1];
     nb[1] = (int)b.size(); nb[0] = n - nb[1];
     nc[1] = (int)c.size(); nc[0] = n - nc[1];
     fo(i, 0, nb[1]){
          fo(j, 0, nc[1]){
               dp[i][j].resize(na[1] + 1, vi(na[0] + 1, -0x3f3f3f3f));
          }
     }
     cout << solve();
}
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     inp();
     sol();
     return 0;
}