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