diff --git a/cpp/2203/220315-CN.cpp b/cpp/2203/220315-CN.cpp new file mode 100644 index 0000000..ae12a3e --- /dev/null +++ b/cpp/2203/220315-CN.cpp @@ -0,0 +1,18 @@ +#include + +class Solution { +public: + static int countMaxOrSubsets(const std::vector& 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; + } +}; diff --git a/cpp/2203/CMakeLists.txt b/cpp/2203/CMakeLists.txt index 3850239..9c7cc24 100644 --- a/cpp/2203/CMakeLists.txt +++ b/cpp/2203/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2203) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2203 220314-CN.cpp) +ADD_EXECUTABLE(2203 220315-CN.cpp)