You are playing a game that starts with a rectangular piece of grid paper. In a move, you cut all remaining pieces of paper with a single cut horizontally or vertically, along a grid line. Thus, if you start the game with a 5 x 6 piece of paper, after the first move you might have a 2 x 6 and a 3 x 6 paper. For the second move, you would then have to divide each of those two pieces.
As a twist to make the game challenging, there is a forbidden size, and at no point in the game play may the width or height of any remaining piece equal the forbidden size (including the initial position).
If, at any point in the game, there are 1 x 1 pieces of paper, they are removed from play. The game is over when no more pieces remain to be cut. You are given ints height and width describing the size of the paper initially, and int forbidden, the forbidden paper size. Return the maximum number of turns you can take before all of the paper has been cut. If it is impossible to play the game through to the end without having a forbidden size, return -1.
|