Answered step by step
Verified Expert Solution
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 #
Implement the following function:
bool canpackageint 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 #
Implement the following function:
void minitemsint items int teams int result int N int M
This function stores in resulti 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 teamsi
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 teamsi
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started