Skip to content

Instantly share code, notes, and snippets.

@whille
whille / t_pack.py
Last active December 31, 2021 09:28
test knapsack, basic dynamic programing problem
import random
import functools
def pack_prestore(ws, avail, vs=None):
"""
ws: weight list, integer
vs: value list; if None, reduced to subset sum problem
use cache to pre store recursive value
return optimal value
hash_sim = (bin(xor).count('0'))/float(d))