Write a program cmsc401.java that reads the size of the rod and cutting points in the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program cmsc401.java that reads the size of the rod and cutting points in the format below: The size of the rod, N, in the first line. N>=2, N =1, M 0 and You are given a rod that is N inches long and a set of M cutting points on the rod. You will need to cut the rod from these M points. You can perform the cuts in any order of these points. After a cut, rod gets divided into two smaller sub- rods. The cost of making a cut is the length of the current sub-rod in which you are making a cut on. Your goal is to minimize the total cost of cutting. Output will show only the minimum cost. Activat Go to Set Input in correct format 10 4 1 5 7 9 Order 1) Cutting at 5: 2) Cutting at 1: 3) Cutting at 7: 4) Cutting at 9: Total Cost: Example Cost 10 5 5 3 0 1 2 3 4 5 6 7 8 9 10 23 Correct output 23 I Cutting points An order of cutting points that gives the min cost is 5,1,7,9 (there are also others giving the same minimum, e.g., 5,7,9,1) Bad cut example: Cutting in the order of 1,5,7,9 which has cost 10+9+5+3=27. Define the problem in terms of cutting the rod from one cutting point to another one - C(i,j) = cost of cutting the rod from point i to point j Find the recursive formula Apply a dynamic programming method Algorithm should have O(M) complexity - M: number of cutting points - Complexity should not depend on N, the length of rod. Activ Write a program cmsc401.java that reads the size of the rod and cutting points in the format below: The size of the rod, N, in the first line. N>=2, N =1, M 0 and You are given a rod that is N inches long and a set of M cutting points on the rod. You will need to cut the rod from these M points. You can perform the cuts in any order of these points. After a cut, rod gets divided into two smaller sub- rods. The cost of making a cut is the length of the current sub-rod in which you are making a cut on. Your goal is to minimize the total cost of cutting. Output will show only the minimum cost. Activat Go to Set Input in correct format 10 4 1 5 7 9 Order 1) Cutting at 5: 2) Cutting at 1: 3) Cutting at 7: 4) Cutting at 9: Total Cost: Example Cost 10 5 5 3 0 1 2 3 4 5 6 7 8 9 10 23 Correct output 23 I Cutting points An order of cutting points that gives the min cost is 5,1,7,9 (there are also others giving the same minimum, e.g., 5,7,9,1) Bad cut example: Cutting in the order of 1,5,7,9 which has cost 10+9+5+3=27. Define the problem in terms of cutting the rod from one cutting point to another one - C(i,j) = cost of cutting the rod from point i to point j Find the recursive formula Apply a dynamic programming method Algorithm should have O(M) complexity - M: number of cutting points - Complexity should not depend on N, the length of rod. Activ
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these algorithms questions
-
In Exercises 1 through 10, determine whether the given function is a probability density function. 10 f(x)= (x + 10) 0 for x 0 for x < 0
-
Find the Fourier transforms of both functions in Fig. 18.31 on the following page. f(t) 10 g(t) 10 0 2 0
-
Does the graph of have a vertical tangent at the origin? Give reasons for your answer. f(x) = -1, 0, 1, x < 0 x = 0 x > 0
-
On July 1, Novak Corporation purchases 570 shares of its $5 par value common stock for the treasury at a cash price of $8 per share. On September 1, it sells 320 shares of the treasury stock for cash...
-
(a) If the symbol [ ] denotes the greatest integer function defined in Example 10, evaluate (i) lim x2+ [x] (ii) lim x2 [x] (iii) lim x2.4 [x] (b) If n is an integer, evaluate (i) lim x n [x] (ii)...
-
Describe the process of communication and its characteristics? Why do we communicate? What qualities make a competent communicator? (Use examples )
-
Consider the National Football League data in Table B.1. Restricting your attention to regressors \(x_{1}\) (rushing yards), \(x_{2}\) (passing yards), \(x_{4}\) (field goal percentage), \(x_{7}\)...
-
Large Land Photo Shop has asked you to determine whether the companys ability to pay current liabilities and total liabilities improved or deteriorated during 2015. To answer this question, you...
-
Drill Problem 7-6 (Algo) [LU 7-1 (4)] Complete the following table: Note: Do not round intermediate calculations. Round your final answers to the nearest cent. Item List price Sony digital camera $...
-
George and Harry Haygood are building contractors who specialize in the construction of private home dwellings, storage warehouses, and small businesses (less than 20,000 sq. ft. of floor space)....
-
1) In 200-300 words wrestle with the issue of Canadian history and identity. To what extent do you think that we should we focus on the big picture (i.e., the meta-narrative or nationalist school) of...
-
Is an increase in the marginal income tax rate reflected by a shift in the after-tax supply of labor or a movement along the supply curve when the pretax wage rate is on the vertical axis? Explain...
-
Using the economic decision rule and opportunity cost, explain why an increase in the wage rate increases quantity of labor supplied?
-
New websites such as iFreelance.com have developed a place for companies to post projects for which freelancers can bid. What is the likely effect of this new market on market demand for freelancers?...
-
Which type of discrimination is easier to address legally demand side or institutional? Explain your answer.
-
a. List three types of demand discrimination. b. Which is the most difficult to eliminate? Why? c. Which is the easiest to eliminate? Why?
-
The last constituent to fail in fiber-reinforced composites is O both matrix and fiber because they fail at the same time O the matrix O the fibers O usually cannot be determined
-
White Bolder Investments (WBI) You are an intern working for WBI, a large investment advisory services in Sydney. Among other regular customers, WBI has been providing advisory services for Jumbo...
-
Carl and Jenny adopt a Russian orphan. The adoption takes 2 years and two trips to Russia and is final in 2012. They pay $6,000 in 2011 and $7,500 in 2012 of qualified adoption expenses, and have AGI...
-
John Fuji (age 37) moved from California to Washington in December 2011. He lives at 468 Cameo Street, Yakima, WA 98901. John's Social Security number is 571-78-5974 and he is single. His earnings...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family. The Incisors own a rental beach house in Hawaii. The beach house was rented for the full year during 2012...
-
Calculate: (a) \(f=a /(b c)\), where \(a=2.34\mathrm{~mm}^{2}, b=54.26\mathrm{~m}\), and \(c=0.14\mu \mathrm{m}\); (b) \(g=k t^{3}\), where \(k=1.208\times 10^{-2}\mathrm{~s}^{-3}\) and...
-
Which of these is a hierarchical approach of subordination of individuals that work together and contribute to serve a common goal? Formal organization Informal structures Functional structure ...
-
A sound organization Prevents corruption Enhances creativity None of the above All of the above
Study smarter with the SolutionInn App