Re: [闲聊] 每日leetcode

楼主: DJYOSHITAKA (Evans)   2024-10-18 23:38:38
先求最大值
然后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]
作者: JerryChungYC (JerryChung)   2024-10-18 23:41:00
不会dp :(

Links booklink

Contact Us: admin [ a t ] ucptt.com