先求最大值
然後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]