Skip to content
CampusEduX

0/1 Knapsack

Mediumjavapythonccppjavascript

Given N items with values and weights and a bag capacity W, choose a subset of items to maximise total value without exceeding the capacity. Each item may be used at most once.

Input Format

The first line contains an integer N. The second line contains N space-separated integers — the values. The third line contains N space-separated integers — the weights. The fourth line contains an integer W, the capacity.

Output Format

Print the maximum total value.

Related Problems

  • House Robber
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Longest Common Subsequence
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Longest Increasing Subsequence
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...