Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Dynamic Programming solution in Clear category for Family Dinner by r_tchaik
from typing import List
from itertools import accumulate
def best_plates(stacks: List[List[int]], guests: int) -> int:
result = [0] * (guests + 1)
for item in stacks:
stack = list(accumulate(item, initial=0))
result = [max(stack[plates] + result[guest - plates]
for plates in range(min(guest + 1, len(stack))))
for guest in range(guests + 1)]
return result[-1]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
print("Example:")
print(best_plates([[10, 10, 100, 30], [80, 50, 10, 50,]], 5))
assert best_plates([[10, 10, 100, 30],
[80, 50, 10, 50,]], 5) == 250, "Example #1"
assert best_plates([[80, 80],
[15, 50],
[20, 10]], 3) == 180, "Example #2"
print("Coding complete? Click 'Check' to earn cool rewards!")
June 9, 2020
Comments: