Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C Code - Recursion Q13. Coupon Madam Tan is a thrifty housewife who loves to collect coupons and use them in all her purchases. She
C Code - Recursion
Q13. Coupon Madam Tan is a thrifty housewife who loves to collect coupons and use them in all her purchases. She has recently collected a set of coupons, each of which allows her to buy a certain number of an item at a certain price (e.g., buy 3 boxes of chocolates at the price of 10 dollars). Each coupon can only be used at most once and cannot be used partially (i.e., the number of items purchased using a coupon must be the same as number specified on the coupon) Now she wants to know what the minimum cost is for buying exactly n units of an item using these coupons only. For example, let say she has 4 coupons: "Buy 3 at 10 dollars", "Buy 2 at 4 dollars", "Buy 2 at 4 dollars" and "Buy 1 at 3 dollars", and she wants to buy 4 units of the item. The minimum cost is then 8 dollars (using the second and the third coupon) Write a recursive function int minimumCost (coupon t coupons [], int numCoupons, int units) to help Madam Tan compute the minimum cost This function should take in a coupon_t array called coupons, which represents the coupons, as well as an integer numCoupons, which represents the number of coupons in the list. This function also takes in another integer units, which represents the number of units to be purchased The structure type definition for coupon_t is as shown below typedef struct ( int quantity; // Number of items purchasable // with this coupon // Total price to be paid for // using this coupon int price; ) coupon t; This function returns the minimum cost if it is possible to make the purchase using these coupons, or -1 otherwise No marks will be given if the function is not recursive [8 marks]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