classSolution { intfindMaximumXOR(unordered_set<int>& a, unordered_set<int>& b){ if(a.size() == 0or b.size() == 0) return0; int res = 0, mask = 0; int bits[128]{}; for(int i = 6; i >= 0; i--) { mask |= 1<<i; int t = res | (1<<i); for(auto& x : a) bits[x & mask] = i + 1; for(auto& x : b) if(bits[(x & mask) ^ t] == i + 1) { res = t; break; } } return res; } public: intmaxValue(vector<int>& nums, int k){ int n = nums.size(), ma = 1<<7; vector<unordered_set<int>> dpl(n), dpr(n); vector<bitset<252>> dp;
auto knapsack = [&](int x) { for(int i = ma - 1; i; i--) { dp[i | x] |= dp[i]<<1; } dp[x][1] = 1; };