Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Preferred language is Python, but C++ is good as well. It must be able to read a txt file of inputs and then post its

Preferred language is Python, but C++ is good as well. It must be able to read a txt file of inputs and then post its results to another txt file. Be sure to read the specifications of the input file (feel free to ask if you need clarification). This is a variant of the knapsack problem, where you must be able to get the maximum price of items that the entire family can carry while also listing the items that each individual family member should select. Use dynamic programming. Please help with all parts and explain your reasoning, especially with understanding how the running time is found (part b). Thank you.

image text in transcribed

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

c) Implement your algorithm by writing a program named shopping. The program should satisfy the specifications below:

Input: The input file named shopping.txt consists of T test cases.

1. T (1

2. Each test case begins with a line containing a single integer number N that indicates the number of items (1

3. Followed by N lines, each containing two integers: P and W. The first integer (1

4. The next line contains one integer (1

5. The next F lines contains the maximum weight (1

Output: Written to a file named results.txt. For each test case your program should output the maximum total price of all goods that the family can carry out during their shopping spree and for each the family member, numbered 1

Sample Input .txt File:

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

36

Sample Output txt File:

Test Case 1

Total Price 72

Member Items

1: 1

Test Case 2

Total Price 568

Member Items

1: 3 4

2: 3 6

3: 3 6

4: 3 4 6

Problem 2: Shopping Spree: (20 points) 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 an item. 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. Write an algorithm to determine the maximum total price of items for each family and the items that each family member should select

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago

Question

Know what customers expect from the firm when they complain.

Answered: 1 week ago

Question

Understand why customers complain.

Answered: 1 week ago