Java domino tiling with recursion: second if block gets called with already updated values

A rectangular grid m x n, should be filled with m*n/2 2x1 dominoes that can be placed horizontally or vertically. How many possible soluitons exist?

I'm trying to solve this problem with recursion (yes I know that this can easily be calculated with fibonacci).

private static void place(int row, int col, int[][] rectangle) {

if (canBePlacedHorizontally(row, col, rectangle)) {

rectangle = deepCopy(rectangle);

placeHorizontally(row, col, rectangle);

decideNextMove(row, col, rectangle);

}

if (canBePlacedVertically(row, col, rectangle)) {

rectangle = deepCopy(rectangle);

placeVertically(row, col, rectangle);

decideNextMove(row, col, rectangle);

}

}

private static void decideNextMove(int row, int col, int[][] rectangle) {

if (rectangleIsFilled(rectangle)) {

count = count.add(BigInteger.ONE);

}

else if(row == rectangle.length -1) {

place(0,...

Read More »

By: StackOverFlow - Monday, 17 September

Related Posts