To cut an 'n' centimeter-long gold bar into 2 pieces costs $n. When a gold bar is cut into many pieces, the order in which the cuts occur can affect the total amount of costs. For example, to cut a 20 centimeter gold bar at length marks 2, 8, and 10 (numbering the length marks in ascending order from the left-hand end, starting from 1). If the cuts to occur in left-to-right order, then the first cut costs $20, the second cut costs $18 (cutting the remaining 18 centimeter bar at originally length mark 8), and the third cut costs $12, totaling $50. If the cuts to occur in right-to-left order, however, then the first cut costs $20 time, the second cut costs $10, and the third cut costs $8, totaling $38. In yet another order, the first cut is at 8 (costing $20), then the 2nd cut is at 2 (costing $8), and finally the third cut is at 10 (costing $12), for a total cost of $40. Given an 'n' centimeter-long gold bar G and an array C[1..m] containing the cutting points in ascending order):
a. Formulate the recursive relation of the optimal solution;
b. Design a bottom-up
c. Analyze the complexity of your algorithm
d. Write an algorithm (pseudo code) to print out a sequence of cuts that achieves this cost.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps
- We have n glasses which can hold a varying amount of liquid. We will say that glass1 is size q1 quarts and glass2 is size q2 quarts, etc. We now give you a size, say x quarts. You must give me a glass of exactly x quarts. You are allowed to fill any glass to exactly its size and to pour any liquid from one glass into another. When you pour, you either have to empty the glass you are pouring from or fill the glass you are pouring into. Can you do it?More concrete example: G1 has size 10 quarts. G2 has size 4 quarts. G3 has size 1 quart. You can get a 5 quart drink by filling G1, pouring 4 quarts from it into G2 and 1 quart of it into G1. After that, G1 has exactly 5 quarts. In the same problem, we could get 8 quarts by filling G2 twice and emptying it into G1 twice. Given This: Write an algorithm to do this and determine its complexity.arrow_forwardSuppose you are a computer salesman and your income depend on the total sales and commissions earned for the computers that you sell. Commission rates vary depending on how many units you sold (see chart below). Your income equals to the total sales plus the commission where the commission equals to total sales times the commission rate. That is, commission = total sales * commission rate and income = total sales + commission. Total Sales Commission rate % Less than 200 sold 8% (totalsales < 200) Greater or equal to 200 sold 10% (totalsales >=200 & totalsales <400) Greater than to 400 sold 12% (if (totalsales >= 400) Use Multiway if, else if (use as many you need) and else correctly Review slides 3-CH-2 Slide 4 and 8 Write the code correctly as show in the chapter slides. Pay attention to the commission chart above: (3) input as examples shown 500, 250, 150 You can work with your team and submit your code and output in PDF. 1. Provide the user the commission rate list…arrow_forwardA performance venue hosts many concerts a year. Performers perform several times a year for the concerts. Each concert has one or more performers and has a name and a specified seating arrangement. A concert is held in one (and only one) of several concert halls, each of which has a room number and the number of seats. Each concert generates revenues from the sales of tickets. Assume that the price of the ticket is the same for the same concert, but different prices for different concerts.Identify several attributes and a key field for each entity. Represent this situation of concerts and performers with an E-R diagramarrow_forward
- Your team was asked to program a self-driving car that reaches its destination with minimum travel time. Write an algorithm for this car to choose from two possible road trips. You will calculate the travel time of each trip based on the car current speed and the distance to the target destination. Assume that both distances and car speed are givenarrow_forwardWhenever you mail a letter, you must decide how much postage to put on the envelope. You like to use this rule of thumb – use a stamp for every five sheets of paper or fraction thereof. For example, if you have 11 sheets of paper, then you use three stamps. Since you’re parsimonious, if an envelope requires more than three stamps, then you simply don’t mail the envelope. Show how the number of stamps per envelope would be calculated. Provide a solution in the form of pseudocode. Your pseudocode must read in appropriate data and print how many stamps to use.arrow_forwardSuppose a person can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a coupon. A person can redeem 3 coupons for one chocolate bar from the machine. This means that once a person has started buying chocolate bars from the machine, he/she always has some coupons. A person would like to know how many chocolate bars can be bought, if a person starts with N dollars and always redeem coupons, if he/she has enough for an additional chocolate bar. For example: With 3 dollars a person could buy 4 chocolate bars after purchasing 3 bars giving him/her 3 coupons and then redeeming the 3 coupons for one bar. This would leave him/her with one extra coupon. Thus, will have 4 chocolate bars and still have one coupon leftover. For 11 dollars, a person can have 16 chocolate bars and still have one coupon leftover. For 12 dollars, a person can have 17 chocolate bars and have two coupons leftover. Write a complete Python program that prompts a buyer to input…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY