【发布时间】:2011-02-11 05:18:43
【问题描述】:
我必须创建一个程序,找到所有可能的方法来填充 x 乘 y 的正方形。您放置一个占用 2 个空间以完全填充的块。
问题是我不知道如何将其编码到您可以记住每个方格的位置的程度。我可以让它完全填满电路板一次,也许两次,但除此之外什么都没有。我也知道我应该使用递归来解决这个问题。这是我到目前为止开始的代码。还有一个主要方法,我的初始偶数/奇数检查工作正常。这是我不知道的部分。
public void recurDomino(int row, int column) {
if (Board[2][x - 1] != false) {
} else if(Board[1][x-1]!=false)
{
}
else {
for (int n=0; n < x - 1; n++) {
Board[row][column] = true;
Board[row][column+1] = true;
column++;
counter++;
}
recurDomino(1, 0);
recurDomino(2, 0);
}
}
Thank you for any help you guys can give me.
******************* EDIT ****************************************
我还是有点困惑。我想出了这个算法,但对于任何大于或等于 2 的值,我总是得到 2。
public boolean tryHorizontal(int row , int col){
if( row < 0 || row >= array[0].length-1)
return false;
else
return true;
}
public boolean tryVertical(int row, int col){
if( col < 0 || col >= 2 )
return false;
else
return true;
}
public boolean tryRowCol(int row, int col){
if(this.tryHorizontal(row, col) && this.tryVertical(row, col)){
return true;
}
else
return false;
}
public int findWays(int row, int col){
int n = 0;
if( !this.tryRowCol(row, col))
return 0;
else
n =+ 1 + this.findWays(row+1, col+1);
return n;
}
【问题讨论】: