-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2044.cpp
More file actions
55 lines (43 loc) · 1.03 KB
/
2044.cpp
File metadata and controls
55 lines (43 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream>
#include<vector>
#include<algorithm>
int countMaxOrSubsets(std::vector<int>& nums) {
int count = 0;
int max = 0;
int sub_max = 0;
std::vector<std::vector<int>> subset = {{}};
for(const auto& num : nums) {
max |= num;
}
for(const auto& num : nums) {
int size = subset.size();
for(int i = 0; i < size; ++i) {
std::vector<int> new_subset = subset[i];
new_subset.push_back(num);
subset.push_back(new_subset);
}
}
for(const auto& a : subset) {
for(const auto& i : a) {
std::cout << i << " ";
}
std::cout << "\n";
}
for(const auto& i : subset) {
sub_max = 0;
for(const auto& n : i) {
sub_max |= n;
}
if(sub_max == max) {
++count;
}
}
return count;
}
using namespace std;
int main() {
vector<int> nums = { 2, 2, 2 };
std::cout << countMaxOrSubsets(nums);
// countMaxOrSubsets(nums);
return 0;
}