PYTHON 迭代方案


  • 0
    Z

    '''
    def mf(s,t):
    for i in range(len(s)):
    if s[i]<t[i]:return False
    return True

        sl=sorted(special,key=lambda x:x[-1], reverse=True)
        ans=sum(map(lambda x,y:x*y,price,needs))
        n=len(needs)
        for i in range(len(sl)):
          r=0
          ds=needs[::]
          for s in sl[i:]:
            while mf(ds,s):
              r+=s[-1]
              for i in range(n):ds[i]-=s[i]
          for i in range(n):r+=ds[i]*price[i]
          ans=min(r,ans)
        return ans
    

    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.