Question
Problem 3: (15 points) Shopping Spree Acme Super Store is having a contest to give away shopping sprees to lucky families. If a family wins
Problem 3: (15 points) Shopping Spree Acme Super Store is having a contest to give away shopping sprees to lucky families. If a family wins a shopping spree each person in the family can take any items in the store that he or she can carry out, however each person can only take one of each type of item. For example, one family member can take one television, one watch and one toaster, while another family member can take one television, one camera and one pair of shoes. Each item has a price (in dollars) and a weight (in pounds) and each person in the family has a limit in the total weight they can carry. Two people cannot work together to carry a single object. Your job is to help the families select items for each person to carry to maximize the total price of all items the family takes. What is the maximum price of items the family can select? Input: The input file named shopping.txt consists of T test cases ? T (1 ? T ? 100) is given on the first line of the input file. ? Each test case begins with a line containing a single integer number N that indicates the number of items (1 ? N ? 100) in that test case ? Followed by N lines, each containing two integers: P and W. The first integer (1 ? P ? 1000) corresponds to the price of object and the second integer (1 ? W ? 100) corresponds to the weight of object. ? The next line contains one integer (1 ? F ? 100) which is the number of people in that family. ? The next F lines contains the maximum weight (1 ? M ? 100) that can be carried by the ith person in the family (1 ? i ? F). Output: Written to a file named shopping.out. For each test case your program should calculate one integer which is the maximum total price of all goods that the family in can carry out during their shopping spree. Sample Input 2 3 72 17 44 23 31 24 1 26 6 64 26 85 22 52 4 99 18 39 13 54 9 4 23 20 20 26 Sample Output 72 514 Submit to Canvas a) A verbal description and give pseudo-code for your algorithm. Try to create an algorithm that is efficient in both time and storage requirements. b) What is the theoretical running time of your algorithm for one test case given N items, a family of size F, and family members who can carry at most Mi pounds for 1 ? i ? F. c) Implement your algorithm by writing a program named shopping.cpp that compiles with g++ on the OSU engineering servers. Submit your code to TEACH in a zipped file. Note: You will not be collecting experimental running rimes. Extra Credit: Determine the exact items each family member should take. Output the family member number 1 ? i ? F and on the same line the item numbers 1 ? N ? 100 that they should select. Describe your algorithm and data structures in detail and give the running time. Name your extra credit program extra.cpp and write the results to a file named extra.out. Submit your code to TEACH in a zip file with the solution to problem 3. Sample Input: 1 3 10 5 20 10 40 15 2 12 28 Sample Output: Total Price 80 Member Items 1: 2 2: 2 3
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