Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The typical unbounded (allowed to choose unlimited amount of each item) knapsack problem can be solved using the following algorithm: // the following algorithm returns

The typical unbounded (allowed to choose unlimited amount of each item) knapsack problem can be solved using the following algorithm:

// the following algorithm returns the maximum value with knapsack of C capacity aka unbounded knapsack

// N = number of types of items, W = weight of each type of item, V = value of each type of item, C = the capacity limit of the knapsack

public static int solve(int N, int[] W, int[] V, int C) { // results[i] is going to store maximum value with knapsack capacity i int results[] = new int[C+1]; // initialise array to 0 Arrays.fill(results, 0); // Fill dp[] using bottom up DP approach for (int i=0; i<=C; i++) for (int j=0; j

How do I go about tweaking this algorithm when there is a new array L[] that stores the quantity of each item? i.e. for each item, there is a limited quantity of it that you can put in the knapsack. In other words, it's a limited bound knapsack problem, where there is a bound in each of the item you are allowed to choose.

I know of the unbounded knapsack algorithm (where you can choose an unlimited amount of each item) and the 1/0 bounded knapsack algorithm (where you can only choose each item once). But what about the limited bound knapsack problem where you can choose more than 1 of each item but there is a limit of each item you can choose?

Thanks in advance!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

3. How has Starbucks changed since its early days?

Answered: 1 week ago