add: 220315-CN [cpp]

This commit is contained in:
Lam Haoyin 2022-03-15 18:59:11 +08:00
parent 74049b8dff
commit aaa07a75df
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 19 additions and 1 deletions

18
cpp/2203/220315-CN.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <vector>
class Solution {
public:
static int countMaxOrSubsets(const std::vector<int>& nums) {
int maxOr = 0;
for (int i : nums)
maxOr |= i;
int n = nums.size(), LIM = 1 << n, ret = 0;
for (int i = 1; i < LIM; ++i) {
int ans = 0;
for (int j = 0; j < n; ++j)
ans |= ((1 << j) & i) ? nums[j] : 0;
ret += ans == maxOr;
}
return ret;
}
};

View File

@ -3,4 +3,4 @@ PROJECT(2203)
SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2203 220314-CN.cpp) ADD_EXECUTABLE(2203 220315-CN.cpp)