We want to display a two-color pattern on a rectangular array of pixels, with k
of the pixels in the foreground color. We want to choose the pattern so that it
minimizes the boundary
between the foreground and the background.
The length of the boundary is the
number of vertical and horizontal pixel edges that separate a foreground pixel
from a background pixel. For example, this picture shows a rectangular array with three rows and six columns that has 5 foreground pixels (indicated by 'X'). The boundary in this case has length equal to 6: the upper left X is adjacent to 1 background pixel,
the upper middle X is adjacent to 1, the rightmost X is adjacent to 3, the lower left X is adjacent to 0, and the lower right X is adjacent to 1.
- - - - - -
X X X - - -
X X - - - -
Create a class Coherence that contains the method
minBndry that takes three int inputs, numRows (the height of the array), numCols (the width of the array), and k (the number of foreground pixels), and returns the length of the minimum possible boundary.
|