Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given an n m Hershey's bar. Your goal is to devise an algorithm A that takes as input (n, m) and returns the

You are given an n m Hershey's bar. Your goal is to devise an algorithm A that takes as input (n, m) and returns the minimal number of cuts needed to divide the bar into perfect squares of either 1x1, 2x2, 3x3, . . ., jxj. With each cut, you can split the bar either horizontally or vertically. The first cut will split the Hershey's bar into two sub-bars; after that each cut splits one remaining sub-bar into two. For example, A(2, 3) = 2 because 2x3 (2x2, 1x2) (2x2, 1x1, 1x1). 1. Hint: Notice that no matter the rectangle input n m, it is always possible to make a perfect square in the first cut. But this strategy will fail. It is possible to find an example input size for which the strategy of picking the cut which creates the largest square leads to extra cuts in total. 2. You can not have fraction, after each cut, the generated rectangles will have integer dimensions (width and height are integer values). 3. Devise a DP algorithm which determines the minimal number of cuts. 4. If your solution has run-time (n 3 ), your solution is acceptable. Discuss the runtime of your algorithm, and show that run-time is equal or below (n 3 ).

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

Fundamentals Of Risk Management

Authors: Clive Thompson, Paul Hopkin

6th Edition

1398602868, 978-1398602861

More Books

Students also viewed these General Management questions

Question

Explain the preliminary data collection methods.

Answered: 1 week ago

Question

What are the purposes of performance appraisals?

Answered: 1 week ago