PPackSerein
Workflows

Coding workflows · Zero-one knapsack value

03
Built around your work

A concrete starting point

Maximize value from at most 64 weight-value pairs with an integer capacity from zero through 1000, using each item once. Test zero capacity and an oversized item, rejecting zero weights or non-integer operands before building the table.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Zero-one knapsack value

A concrete starting point
def knapsack_value(items, capacity):
    items = tuple(tuple(item) for item in items)
    if type(capacity) is not int or not 0 <= capacity <= 1000:
        raise ValueError("capacity.range")
    if len(items) > 64 or any(len(item) != 2 for item in items):
        raise ValueError("items.shape")
    if any(type(w) is not int or type(v) is not int or not 1 <= w <= 1000 or not 0 <= v <= 1000000 for w, v in items):
        raise ValueError("item.range")
    best = [0] * (capacity + 1)
    for weight, value in items:
        for limit in range(capacity, weight - 1, -1):
            best[limit] = max(best[limit], best[limit - weight] + value)
    return best[capacity]

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗