2025-07-10 14:13:01 +08:00
|
|
|
struct Solution;
|
|
|
|
impl Solution {
|
2025-07-28 11:18:09 +08:00
|
|
|
pub fn count_max_or_subsets(nums: Vec<i32>) -> i32 {
|
|
|
|
let max_or = nums.iter().fold(0, |acc, &x| acc | x);
|
|
|
|
let mut dp = vec![0;1<<nums.len()];
|
|
|
|
for i in 0..nums.len() {
|
|
|
|
for j in (1<<i)..(1<<(i+1)) {
|
|
|
|
dp[j] = dp[j - (1<<i)] | nums[i];
|
2025-07-22 21:59:38 +08:00
|
|
|
}
|
2025-07-26 23:49:26 +08:00
|
|
|
}
|
2025-07-28 11:18:09 +08:00
|
|
|
dp.iter().filter(|x| **x == max_or ).count() as i32
|
2025-07-10 14:13:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2025-07-28 11:18:09 +08:00
|
|
|
let sl = Solution::count_max_or_subsets(vec![3,2,1,5]);
|
2025-07-10 14:13:01 +08:00
|
|
|
println!("{}", sl);
|
|
|
|
}
|
2025-07-26 23:49:26 +08:00
|
|
|
|