先求最大值
然后dp吧
这dp写到我自己都觉得恶心了
丑丑丑
def countMaxOrSubsets(self, nums: List[int]) -> int:
maximum = 0
for num in nums:
maximum = maximum | num
mp = defaultdict(int)
mp[0] = 1
for num in nums:
tmp = defaultdict(int)
for k in list(mp.keys()):
if num|k < maximum:
tmp[num|k] += mp[k]
else:
tmp[maximum] += mp[k]
for k,v in tmp.items():
mp[k] += v
return mp[maximum]