public class ChessBoard
{
int tile = 1;
int k = 16;
int[][] Board = new int[16][16];
public void ChessBoard(int tr,int tc,int dr,int dc,int size)
{
if(size == 1) return;
int t = tile++;
System.out.println(t);
int s = size/2;
if(dr < tr+s && dc <tc + s) //如果特别点在左上脚
{
ChessBoard(tr,tc,dr,dc,s);
}
else
{
Board[tr+s-1][tc+s-1] = t;
ChessBoard(tr,tc,tr+s-1,tc+s-1,s);
}
if(dr >= tr+s && dc<tc+s) //如果特别点在左下角
{
ChessBoard(tr+s,tc,dr,dc,s);
}
else
{
Board[tr+s][tc+s-1] = t;
ChessBoard(tr+s,tc,tr+s,tc+s-1,s);
}
if(dr < tr+s && dc >=tc+s)//如果特别点在右上角
{
ChessBoard(tr,tc+s,dr,dc,s);
}
else
{
Board[tr+s-1][tc+s] = t;
ChessBoard(tr,tc+s,tr+s-1,tc+s,s);
}
if(dr >= tr+s && dc >= tc+s)//如果特别点在右下角
{
ChessBoard(tr+s,tc+s,dr,dc,s);
}
else
{
Board[tr+s][tc+s] = t;
ChessBoard(tr+s,tc+s,tr+s,tc+s,s);
}
}
public void printA()
{
for(int i = 0 ; i<k;i++)
{
for(int j = 0;j<k;j++)
{
System.out.print(" "+Board[i][j]);
if(j==15)System.out.println('\t');
}
}
}
public static void main(String args[])
{
ChessBoard cb = new ChessBoard();
cb.ChessBoard(0,0,0,0,16);
cb.printA();
}
}
在一个2k x 2k ( 即:2^k x 2^k )个方格组成的棋盘中,恰有一个方格与其他方格不同,称该方格为一特殊方格,且称该棋盘为一特殊棋盘。在棋盘覆盖问题中,要用图示的4种不同形态的L型骨牌覆盖给定的特殊棋盘上除特殊方格以外的所有方格,且任何2个L型骨牌不得重叠覆盖。