The way to regain the algorithm--board cover

Source: Internet
Author: User

*************************************** Reprint Please specify the Source: Http://blog.csdn.net/lttree ********************************************


Subordinate to recursion and division


Board coverage issues


Problem Description:  

In a chessboard of 2^kx2^k squares, if a square is different from other squares, it is a special square and is called a special chessboard. In the board coverage problem, the four ' l ' type dominoes shown cover all squares in a given special checkerboard except for special squares, and any two ' l ' type dominoes cannot overlap. (and know that in any 2^KX2^K board cover, the number of L-type dominoes used is exactly (4^k-1)/3.)




Problem Solving: the problem is solved by a divide-and-conquer strategy,

When k > 0 o'clock, the 2^kx2^k chessboard is divided into 4 2^ (k-1) x2^ (k-1) sub-chessboard, such as:


Special squares must be located in one of the four boys ' chessboard, and there are no special squares in the remaining three chessboard.

In order to cover the remaining three sub-chessboard with the ' L ' type dominoes, a special square is set in each checkerboard,

It can be found that these three squares can form an ' L ' type Domino, such as:


In this way, it is possible to recursively go down until the board is 1x1 in size.



Algorithm code:

<span style= "Font-family:comic Sans ms;font-size:14px;"    >void cheseboard (int lr, int lc, INT sr, int SC, int _size) {if (_size = = 1) return;    int t = tile++, s = _SIZE/2;    Determine if the special lattice is in the upper left corner of the four regions if (SR < LR + S && SC < LC + s) cheseboard (lr,lc,sr,sc,s);        else {board[lr+s-1][lc+s-1]=t;    Cheseboard (lr,lc,lr+s-1,lc+s-1,s);    }//Determine if the special lattice is in the upper right corner of the four regions if (SR < LR + S && SC >= LC + s) cheseboard (lr,lc+s,sr,sc,s);        else {board[lr+s-1][lc+s]=t;    Cheseboard (lr,lc+s,lr+s-1,lc+s,s);    }//Determine if the special lattice is in four areas in the lower left corner area if (SR >= LR + S && SC < LC + s) cheseboard (lr+s,lc,sr,sc,s);        else {board[lr+s][lc+s-1]=t;    Cheseboard (lr+s,lc,lr+s,lc+s-1,s);    }//Determine if the special lattice is in the lower right corner of the four regions if (SR >= LR + S && SC >= LC + s) cheseboard (lr+s,lc+s,sr,sc,s);        else {board[lr+s][lc+s]=t;  Cheseboard (lr+s,lc+s,lr+s,lc+s,s);  }}</span> 

there should be no need to explain a lot, simply say the meaning of each parameter:

LR,LC Horizontal and vertical axis in the upper left corner

Horizontal and vertical axis of SR,SC special lattice

_size size of the chessboard (chessboard to 2^k)



Algorithm Analysis:

Set T (k) is the time required for the algorithm Cheseboard to cover a 2^kx2^k chessboard, which can be calculated from the algorithm's divide-and-conquer strategy:

T (k)= O (1) when k=0

=4*t (k-1) +o (1) when k>0

The recursive equation can be solved by T (k) = O (4^k).



*************************************** Reprint Please specify the Source: Http://blog.csdn.net/lttree ********************************************


The way to regain the algorithm--board cover

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.