看板 Marginalman
先求最大值 然後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] -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.228.146.144 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1729265920.A.FC0.html