Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview You are given the following: A list of food items, each with a number of calories. A list of teams, each with a number

Overview
You are given the following:
A list of food items, each with a number of calories.
A list of teams, each with a number of needed calories (calculated based on the team size, type of sport, etc.)
You would like to prepare a package of food items for every team, such that the total calories of the items in the package equals exactly the needed calories by the team. Assume that:
You have an infinite supply of the items.
A package can have an item multiple times (we care most about the total number of calories).
An item can't be broken into fractions.
Task # 1
Implement the following function:
bool can_package(int items[], int N, int C)
This function returns true if there is a way to create a package using the given items, such that the total calories in the package equals exactly C. The function returns false otherwise.
Task # 2
Implement the following function:
void min_items(int items[], int teams[], int result[], int N, int M)
This function stores in result[i] the minimum number of items needed to create a package for team
i, such that the total number of calories in the package equals exactly teams[i].
Note. Assume that there will always be a way to create a package for team
i such that the total calories in the package equals teams[i].

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

2. List the advantages of listening well

Answered: 1 week ago