You have a rectangular sheet of paper, from which you wish to cut a pattern. The pattern is a figure composed of unit squares. You wish to cut out as many instances of the pattern as possible from the sheet of paper. The pattern may be cut out exactly as is, or may be rotated 90 or 180 degrees (in either direction).
You are given ints height and width, describing the size of the sheet of paper, and a String[] pattern that defines the pattern you want to cut out. pattern is composed of 'X' characters and period ('.') characters, where 'X' is part of the pattern, and '.' is not. The following respresents the 7 valid patterns with 4 'X's (ignoring rotations of the same pattern):
{"XXXX"}
{"XXX",
"X.."}
{"XXX",
"..X"}
{"XXX",
".X."}
{"XX.",
".XX"}
{"X.",
"XX",
".X"}
{"XX",
"XX"}
So, for the T-shaped pattern, from a 4 x 5 sheet of paper, you could cut out the pattern four times. One way would be like this:
A.BBB
AA.BC
AD.CC
DDD.C
You are to return an int indicating the maximum number of times the given pattern can be cut from the sheet of paper.
|