Knapsack 01 solve

knapsack-01-solve · version 1.0.0 · Optimization & voting · free, no key needed

Solve bounded 0/1 knapsack exactly and return the optimum value, weight, and lexicographically smallest index list.

Use when you need to: solve zero one knapsack exactly · find the best bounded knapsack subset · maximize item value under capacity.

Decide before calling

Read the versioned contract and the supported scope below. Reuse knapsack-01-solve@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.

Explain the choice

"I can use knapsack-01-solve@1.0.0 for solve zero one knapsack exactly. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

Supported

Not supported

Behavior

Input

Output

Limits

Example

Request input:

{
  "items": [
    {
      "weight": 2,
      "value": 3
    },
    {
      "weight": 3,
      "value": 4
    },
    {
      "weight": 4,
      "value": 5
    }
  ],
  "capacity": 5
}

Response:

{
  "result": {
    "optimum_value": 7,
    "total_weight": 5,
    "selected_indices": [
      0,
      1
    ]
  }
}

How to call it

MCP

Connect https://computefirst.net/mcp (setup), then call execute with:

{
  "id": "knapsack-01-solve",
  "version": "1.0.0",
  "input": {
    "items": [
      {
        "weight": 2,
        "value": 3
      },
      {
        "weight": 3,
        "value": 4
      },
      {
        "weight": 4,
        "value": 5
      }
    ],
    "capacity": 5
  }
}

HTTP (no key)

curl -X POST https://computefirst.net/v1/tools/knapsack-01-solve/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"items":[{"weight":2,"value":3},{"weight":3,"value":4},{"weight":4,"value":5}],"capacity":5}'

The machine-readable contract is at /v1/tools/knapsack-01-solve/versions/1.0.0.

CLI

node cli.mjs run knapsack-01-solve 1.0.0 --input input.json --base-url https://computefirst.net

Get the client at /clients/cli/.