/*! 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} 5E Pebbling a checkerboard. We are ... [FREE SOLUTION] | 91影视

91影视

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, 鈥榅鈥 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:鈥勨赌刦辞谤yfrom0to7鈥勨赌勨赌勨赌刴补虫=0鈥勨赌勨赌勨赌m=Sumx,y鈥勨赌勨赌勨赌forpincompatibilityy鈥勨赌勨赌勨赌勨勨n=Sumx1,p鈥勨赌勨赌勨赌勨勨刬fm+n>max鈥勨赌勨赌勨赌勨勨赌勨赌勨赌勨則henmax=m+n鈥勨赌勨赌勨赌勨勨Ax,y=maxreturnMax(Ai,N蹿辞谤补濒濒鈥刬

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 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

You are given a string of n characters s[1...n], which you believe to be a corrupted text document in which all punctuation has vanished (so that it looks something like 鈥渋twasthebestoftimes...鈥). You wish to reconstruct the document using a dictionary, which is available in the form of a Boolean function dict(.): for any string w,

dict(w)={trueifwisavalidwordfalseotherwise

Give a dynamic programming algorithm that determines whether the string s[.]can be reconstituted as a sequence of valid words. The running time should be at mostO(n2) , assuming calls to dict take unit time.

In the event that the string is valid, make your algorithm output the corresponding sequence of words.

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).

The garage sale problem (courtesy of Professor Lofti Zadeh). On a given Sunday morning, there are n garage sales going on, g1,g2,g3............gn. For each garage sale gj, you have an estimate of its value to you, vj. For any two garage sales you have an estimate of the transportation cost dijof getting from gito gj. You are also given the costs d0jand dj0of going between your home and each garage sale. You want to find a tour of a subset of the given garage sales, starting and ending at home, that maximizes your total benefit minus your total transportation costs. Give an algorithm that solves this problem in time O(n22n).

(Hint: This is closely related to the traveling salesman problem.)

Given two strings x=x1x2xnand y=y1y2ym, we wish to find the length of their longest common subsequence, that is, the largest k for which there are indices i1<i2<<ikand j1<j2<<jkwith xi1xi2xik=yj1yj2yjk. Show how to do this in time 0(mn).

Given two strings x=x1x2xnand y=y1y2ym, we wish to find the length of their longest common substring, that is, the largest k for which there are indices i and j with xixi+1xi+k-1=yjyj+1yj+k-1. Show how to do this in time0(mn)

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.