Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Pebbling a checkerboard. We are given a checkerboard which has 4 rows and ncolumns, and has an integer written in each square. We are also given a set of 2n pebbles, and we want to place some or all of these on the checkerboard (each pebble can be placed on exactly one square) so as to maximize the sum of the integers in the squares that are covered by pebbles. There is one constraint: for a placement of pebbles to be legal, no two of them can be on horizontally or vertically adjacent squares (diagonal adjacency is fine).

  1. Determine the number of legal patterns that can occur in any column (in isolation, ignoring the pebbles in adjacent columns) and describe these patterns.

Call two patterns compatible if they can be placed on adjacent columns to form a legal placement. Let us consider subproblems consisting of the first columns 1kn. Each subproblem can be assigned a type, which is the pattern occurring in the last column.

  1. Using the notions of compatibility and type, give an O(n)-time dynamic programming algorithm for computing an optimal placement.

Short Answer

Expert verified
  1. There are 8possible patterns which can be legally occur according to the given constraint.
  2. For each pattern, there is set of compatible patterns. Split the problem into subproblems and find the optimal value by pebbling column i with patten j. Create separate arrays for each pattern type.

Step by step solution

01

Consider the given information

The checkboard has 4 rows and ncolumns. 2npebbles need to be placed on the check board such that they are legal patterns. The condition for the pattern to be legal is that no two pebbles can be placed on vertically or horizontally adjacent squares.

02

Determining the legal patterns

The following table shows are possible patterns with the given constraint:

Pattern

Description

_ _ _ _

No Pebble in any Row

X _ _ _

Pebble at 1st Row

_ X _ _

Pebble at 2nd Row

_ _ X _

Pebble at 3rd Row

_ _ _ X

Pebble at 4th Row

X _ _ X

Pebble at 1st and 4th Row

_ X _ X

Pebble at 2nd and 4th Row

X _ X _

Pebble at 1st and 3rd Row

Here, ‘X’ denotes Pebble position and ‘_’ denotes empty place.

Thus, the possible legal patterns are 8.

03

Determine the dynamic programming to compute optimal placement

Consider the initial checkboard be M[i,j]. The method compatibility (i) gives the patterns compatible with i. In the array A[i,j], i denotes pattern and j denotes column. Sum (i, j) method returns the sum of numbers on column i when pattern j is applied.

Ai,0=0foralliforxfrom1ton:  foryfrom0to7    max=0    m=Sumx,y    forpincompatibilityy      n=Sumx1,p      ifm+n>max         thenmax=m+n      Ax,y=maxreturnMax(Ai,Nforall i

The time complexity of the algorithm is O(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 Vaia!

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

Yuckdonald’s is considering opening a series of restaurant along Quaint Valley Highway(QVH). The n possible locations are along a straight line, and the distances of these locations from the start of QVH are, in miles and in increasing order,m1,m22,....,mn.. The constraints are as follows:

At each location, Yuckdonald may open at most one restaurant. The expected profit from opening a restaurant at location i is given aspi, wherepi>0andi=1,2,,n.

Any two restaurants should be at least k miles apart, where k is a positive integer.

Give an efficient algorithm to compute the maximum expected total profit subject to the given constraints.

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’s add up to t? (You can use each ai at most once.) (Hint: Look at subproblems of the form “does a subset of{a1,a2,...,ai} add up to ?”)

A mission-critical production system has n stages that have to be performed sequentially; stage i is performed by machine Mi. Each machine Mi has a probability riof functioning reliably and a probability 1-riof failing (and the failures are independent). Therefore, if we implement each stage with a single machine, the probability that the whole system works is r1·r2···rn. To improve this probability we add redundancy, by having mi copies of the machine Mi that performs stage i. The probability that all mi copies fail simultaneously is only (1-ri)mi,so the probability that stage i is completed correctly is 1 − (1-ri)mi, and the probability that the whole system works isΠni=1(1-1-rimi).Each machine has a cost ci, and there is a total budget to buy machines. (Assume that B and ciare positive integers.) Given the probabilities r1·r2···rn, the costsc1,...,cn, and the budget find the redundanciesm1,...,mn that are within the available budget and that maximize the probability that the system works correctly.

Consider the following 3-PARTITION problem. Given integersa1,...,an, we want to determine whether it is possible to partition of {1,...,n} into three disjoint subsets I,J,Ksuch that

aiiI=ajjJ=akkk=13aii1 .

For example, for input(1,2,3,4,4,5,8) the answer is yes, because there is the partition(1,8),(4,5),(2,3,4). On the other hand, for input(2,2,3,5) the answer is no. Devise and analyze a dynamic programming algorithm3-PARTITION for that runs in time polynomial in n and in Σiai.

You are going on a long trip. You start on the road at mile post 0. Along the way there aren hotels, at mile posts a1<a2<...<an , where eachai is measured from the starting point. The only places you are allowed to stop are at these hotels, but you can choose which of the hotels you stop at. You must stop at the final hotel (at distance an), which is your destination. You’d ideally like to travel miles a day, but this may not be possible (depending on the spacing of the hotels). If you travel x miles during a day, the penalty for that day is (200x)2. You want to plan your trip so as to minimize the total penalty- that is, the sum, over all travel days, of the daily penalties.Give an efficient algorithm that determines the optimal sequence of hotels at which to stop

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.

Sign-up for free