#include <STDIO.H>
#include "stdlib.h"
#include "process.h"
#include <math.h>
int tile=0;
int ** board=NULL;
void chessBoard(int tr, int tc, int dr, int dc, int size)
{
if (size == 1) return;
int t = ++tile; // L型骨牌号
int s = size/2; // 分割棋盘
// 覆盖左上角棋盘
if (dr < tr + s && dc < tc + s)
// ?????????
chessBoard(tr, tc, dr, dc, s);
else {// ?????????
// ? t ?L????????
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, tc+s, dr, dc, s);
else {// ?????????
// ? t ?L????????
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, dr, dc, s);
else {// ? t ?L????????
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+s, tc+s, dr, dc, s);
else {// ? t ?L????????
board[tr + s][tc + s] = t;
// ??????
chessBoard(tr+s, tc+s, tr+s, tc+s, s);}
}
int main()
{
int tr=0,tc=0,dr=0,dc=0,size=0,i,j;
printf("请输入行号列号和以及棋盘的规模\n");
scanf("%d%d%d",&dr,&dc,&size);
board=(int **)malloc(sizeof(int *)*(int)pow(2,size));
for (i=0;i<pow(2,size);i++)
{
*(board+i)=(int *)malloc(sizeof(int)* (int)pow(2,size));
}
for (i=0;i<pow(2,size);i++)
{
for (j=0;j<pow(2,size);j++)
{
board[i][j]=0;
}
}
//特殊方格所在的位置为-1
board[dr][dc]=-1;
printf("\n");
chessBoard(tr,tc,dr,dc,(int)pow(2,size));
printf("求解如下,-1代表特殊方格的位置:\n");
for (i=0;i<pow(2,size);i++)
{
for (j=0;j<pow(2,size);j++)
printf("%3d ",board[i][j]);
printf("\n");
printf("\n");
}
printf("\n");
system("pause");
return 0;
}