/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} 14E Cutting cloth. You are given a r... [FREE SOLUTION] | 91影视

91影视

Cutting cloth. You are given a rectangular piece of cloth with dimensions XY, whereX and Yare positive integers, and a list of products that can be made using the cloth. For each producti[1,n] you know that a rectangle of cloth of dimensionsaibi is needed and that the final selling price of the product is ci. Assume the,ai biandci are all positive integers. You have a machine that can cut any rectangular piece of cloth into two pieces either horizontally or vertically. Design an algorithm that determines the best return on theXY piece of cloth, that is, a strategy for cutting the cloth so that the products made from the resulting pieces give the maximum sum of selling prices. You are free to make as many copies of a given product as you wish, or none if desired.

Short Answer

Expert verified

Using dynamic programming, the required algorithm can be implemented with time complexity OXYX+Y+n.

Step by step solution

01

Defining recursive relation

ConsiderCUTi,j be the cut made in order to make maximum selling cost.

Base case is when no cut is made,i=j=0 which give CUTi,j=0.

To cut horizontally, alongx, the recursive relation is

CUTi,j=maxCUTi,j,CUTicut,j+CUTiicut,j

To cut vertically, along,y the recursive relation is

CUTi,鈥j=maxCUTi,鈥j,CUTi,鈥jcut+CUTi,jjcut

From these two recurrence relation, dimension of cloth required to make maximum selling price.

02

Determine an algorithm

The algorithm is given as follows:

fori=0鈥则辞x-1鈥勨赌勨赌刦辞谤j=0鈥则辞鈥Y1鈥勨勨勨勨赌勨赌刦辞谤icut=1鈥则辞鈥i1鈥勨赌勨赌勨赌勨赌勨赌勨赌勨赌勨赌CUTi,j=maxCUTi,j,CUTicut,j+CUTiicut,j

鈥勨勨勨勨赌勨赌刦辞谤jcut=1鈥则辞j1鈥勨赌勨赌勨赌勨赌勨赌勨赌勨赌勨赌CUTi,j=maxCUTi,j,CUTi,jcut+CUTi,jjcut鈥勨勨勨勨赌勨赌刦辞谤颈迟别尘鈥刬苍滨罢贰惭厂鈥勨赌勨赌勨赌勨赌勨赌勨赌勨赌勨赌刬fitemdimension=i,j鈥勨赌勨赌勨赌勨赌勨赌勨赌勨赌勨赌勨勨勨CUTi,j=maxCUTi,j,ci谤别迟耻谤苍鈥CUTX1,Y1

The algorithm returns the desired size of cloth need to earn maximum selling price.

03

Analyse the run time of the algorithm 

The inner three for()loops runX,Y andn times, so runtime for inner loops are OX+Y+nNow outer loops run in nesting, that give OXY.

Thus, effective runtime is OXYX+Y+n.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with 91影视!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Give an O(nt) algorithm for the following task. Input: A list of n positive integers a1,a2,...,an; a positive integer t. Question: Does some subset of the ai鈥檚 add up to t? (You can use each ai at most once.) (Hint: Look at subproblems of the form 鈥渄oes a subset of{a1,a2,...,ai} add up to ?鈥)

You are given a convex polygon P on n vertices in the plane (specified by their x and y coordinates). A triangulation of P is a collection of n-3diagonals of such that no two diagonals intersect (except possibly at their endpoints). Notice that a triangulation splits the polygon鈥檚 interior into n-2 disjoint triangles. The cost of a triangulation is the sum of the lengths of the diagonals in it. Give an efficient algorithm for finding a triangulation of minimum cost. (Hint: Label the vertices of P by 1,....,n, starting from an arbitrary vertex and walking clockwise. For 1i<jn, let the subproblem A(i,j)denote the minimum cost triangulation of the polygon spanned by vertices i,i+1,...,j.).

Suppose two teams, A and B, are playing a match to see who is the first to win games (for some particular n). We can suppose that A and B are equally competent, so each has a 50% chance of winning any particular game. Suppose they have already played i+j games, of which A has won i and B has won j. Give an efficient algorithm to compute the probability that A will go on to win the match. For example, if i=n-1 and j=n-3 then the probability that A will win the match is 78, since it must win any of the next three games.

A certain string-processing language offers a primitive operation which splits a string into two pieces. Since this operation involves copying the original string, it takes n units of time for a string of length n, regardless of the location of the cut. Suppose, now, that you want to break a string into many pieces. The order in which the breaks are made can affect the total running time. For example, if you want to cut a 20-character string at positions 3 and 10, then making the first cut at position 3 incurs a total cost of 20+17=37, while doing position first has a better cost of 20+17=37.

Give a dynamic programming algorithm that, given the locations of m cuts in a string of length , finds the minimum cost of breaking the string into m +1 pieces.

Consider the following variation on the change-making problem (Exercise 6.17): you are given denominations x1,x2,...,xn, and you want to make change for a value v, but you are allowed to use each denomination at most once. For instance, if the denominations are 1,5,10,20,then you can make change for 16=1+15and for 31=1+10+20but not for 40(because you can鈥檛 use 20 twice).

Input: Positive integers; x1,x2,...,xnanother integer v.

Output: Can you make change for v, using each denominationxi at most once?Show how to solve this problem in time O(nV).

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.