Problem Statement
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
{"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
Definition
- Class:
- PatternCutting
- Method:
- getMax
- Parameters:
- int, int, String[]
- Returns:
- int
- Method signature:
- int getMax(int width, int height, String[] pattern)
- (be sure your method is public)
Constraints
- height and width will be between 1 and 6, inclusive.
- pattern will contain between 1 and 6 elements, inclusive.
- Each element of pattern will contain between 1 and 6 characters, inclusive.
- Each element of pattern will contain the same number of characters.
- Each character of each element of pattern will be 'X' or '.'.
- The first character of the first element of pattern will be 'X'.
- Each block of the pattern will be connected (horizontally or vertically) to the rest of the pattern.
- The pattern will not contain any empty rows or columns (it will not be "padded").
Examples
4
5
{"XXX", ".X."}
Returns: 4
As in the problem statement, you can cut out the T pattern four times.
6
5
{"XX", "XX"}
Returns: 6
Although there are 30 unit squares in the paper and only four used by our pattern, we are going to waste at least 6 squares from which we cannot cut another pattern. We can cut out no more than 6 of the pattern.
4
3
{"XXXXX", "XX..."}
Returns: 0
Here, our pattern is simply too large to cut from the paper, so we can't cut it out at all.
6
6
{"X"}
Returns: 36
6
6
{"XX"}
Returns: 18
6
6
{"XX.", ".XX"}
Returns: 7
6
6
{"XX.", ".X.", ".XX"}
Returns: 5
6
6
{"XX.", ".XX", "..X"}
Returns: 6
6
6
{"XXX", "X.X", "XXX"}
Returns: 4
4
5
{"XXX", ".XX"}
Returns: 4
6
5
{"XX", "X."}
Returns: 10
3
2
{"XX","X."}
Returns: 2
6
6
{"X" }
Returns: 36
6
5
{"X.", "XX" }
Returns: 10
6
6
{"X.", "XX" }
Returns: 12
6
6
{"XXX", "X.X" }
Returns: 6
6
5
{"XX", "X." }
Returns: 10