bilingual-math-code-verification-v1 / code /math_code_003_verify.py
efe-T's picture
Upload folder using huggingface_hub
93237a0 verified
Raw History Blame Contribute Delete
649 Bytes
from itertools import combinations
items = [("A", 2, 3), ("B", 3, 4), ("C", 4, 5), ("D", 5, 8), ("E", 9, 10)]
feasible = []
for size in range(6):
for subset in combinations(items, size):
weight = sum(x[1] for x in subset)
value = sum(x[2] for x in subset)
if weight <= 10:
feasible.append(([x[0] for x in subset], weight, value))
best_value = max(x[2] for x in feasible)
best = [x for x in feasible if x[2] == best_value]
assert len(best) == 1
names, weight, value = best[0]
result = {"items": names, "weight": weight, "value": value}
import json
print(json.dumps(result, ensure_ascii=False, sort_keys=True))