Dancing Links~~~

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2518

Dominoes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 31    Accepted Submission(s): 8


Problem Description

Some day, Tom's father buys him a box of dominoes blocks. In the box, there are 12 different blocks, which are shown above. Tom is a boy who likes to do practice in intelligence, so he spends a whole afternoon in finishing two different rectangles with 3 * 20, which are shown below.

①⑤⑤⑤⑤⑨⑩⑩⑩⑥⑥⑧②②②②②③④④
①⑤⑿⑿⑨⑨⑨⑩⑥⑥⑦⑧⑧⑧⑾⑾③③③④
①①①⑿⑿⑿⑨⑩⑥⑦⑦⑦⑦⑧⑾⑾⑾③④④

①⑧⑦⑦⑦⑦⑥⑩⑨⑿⑿⑿②②②②②③④④
①⑧⑧⑧⑦⑥⑥⑩⑨⑨⑨⑿⑿⑤⑾⑾③③③④
①①①⑧⑥⑥⑩⑩⑩⑨⑤⑤⑤⑤⑾⑾⑾③④④

Tom is sure that these are the only solutions for 3 * 20, and he wants to know the number of solutions for 4 * 15, 5 * 12, ... Can you help him?

You should notice that if a solution will be the same as the other by some flip or rotate, these two solutions should be consider as the same.
 


 

Input
There may be several test cases. Each contains a single line with two positive integers M and N, which means the shape of M * N. Here M * N = 60.
 


 

Output
For each test case, output a line contains the number of solutions.
 


 

Sample Input
1 60 3 20
 


 

Sample Output
0 2

好些天之前写的题了,思路比较简单,不过代码量比较大。。

需要判断出每个图形有几种旋转方式。 建立矩阵,列数数72,60个小方格,外加12个图形限制,每个图形只能用一次。。

因为只有6中情况,所以要先用自己的代码跑出每组例子,然后直接输出结果就ok了。

若是直接把代码提交上去而不进行这样猥琐的处理,估计没有不超时的~~

此题不贴代码了,因为总共就8人过,,保留一些悬念比较好。 ^_^。。

贴一下我总结的旋转规律:

int map1[4][5][2]={0,0,1,0,2,0,2,1,2,2, 0,0,0,1,0,2,1,0,2,0, 0,0,0,1,0,2,1,2,2,2,  0,2,1,2,2,2,2,1,2,0};
    int map4[4][5][2]={0,-1,0,1,1,-1,1,0,1,1 , -1,0,1,0,-1,1,0,1,1,1, 0,-1,0,1,-1,-1,-1,0,-1,1, -1,0,1,0,-1,-1,0,-1,1,-1};
    int map5[8][5][2]={0,0,1,0,1,1,1,2,1,3 ,0,0,0,1,-1,1,-2,1,-3,1 ,0,0,-1,0,-1,-1,-1,-2,-1,-3,  0,0,0,-1,1,-1,2,-1,3,-1
    ,0,0,1,0,1,-1,1,-2,1,-3,  0,0,0,-1,-1,-1,-2,-1,-3,-1, 0,0,-1,0,-1,1,-1,2,-1,3, 0,0,0,1,1,1,2,1,3,1};//
    int map6[4][5][2]={0,0,1,0,1,1,2,1,2,2, 0,2,1,2,1,1,2,0,2,1, 0,0,0,1,1,1,1,2,2,2,  0,1,0,2,1,0,1,1,2,0};
    int map7[8][5][2]={0,0,1,-1,1,0,1,1,1,2,  0,0,0,1,1,1,-1,1,-2,1,  0,0,-1,0,-1,1,-1,-1,-1,-2,  0,0,-1,-1,0,-1,1,-1,2,-1,
    0,0,1,0,1,1,1,-1,1,-2, 0,0,0,-1,1,-1,-1,-1,-2,-1, 0,0,-1,-1,-1,0,-1,1,-1,2,  0,0,-1,1,0,1,1,1,2,1};
    int map8[4][5][2]={0,2,1,2,1,1,1,0,2,0,  0,0,0,1,1,1,2,1,2,2, 0,0,1,0,1,1,1,2,2,2, 0,1,0,2,1,1,2,1,2,0};
    int map9[8][5][2]={0,0,0,-1,-1,0,-1,1,-2,0,  0,0,0,1,-1,0,-2,0,-1,-1, 0,0,-1,0,0,1,0,2,1,1, 0,0,1,0,0,1,0,2,-1,1,
    0,0,0,-1,1,0,2,0,1,1, 0,0,0,1,1,0,2,0,1,-1, 0,0,1,0,0,-1,0,-2,-1,-1, 0,0,-1,0,0,-1,0,-2,1,-1};
    int map10[4][5][2]={0,0,0,-1,0,1,-1,0,-2,0,  0,0,-1,0,1,0,0,1,0,2,  0,0,0,-1,0,1,1,0,2,0, 0,0,-1,0,1,0,0,-1,0,-2};
    int map11[8][5][2]={0,0,0,1,1,-1,1,0,1,1, 0,0,0,-1,1,-1,1,0,1,1, 0,0,-1,0,-1,1,0,1,1,1, 0,0,1,0,1,1,0,1,-1,1,
    0,0,0,1,-1,-1,-1,0,-1,1, 0,0,0,-1,-1,-1,-1,0,-1,1, 0,0,-1,0,-1,-1,0,-1,1,-1, 0,0,1,0,-1,-1,0,-1,1,-1};
    int map12[8][5][2]={0,0,1,0,1,-1,0,1,0,2,  0,0,1,0,1,1,0,-1,0,-2,  0,0,0,1,1,1,-1,0,-2,0, 0,0,0,1,-1,1,1,0,2,0,
    0,0,-1,0,-1,-1,0,1,0,2, 0,0,-1,0,-1,1,0,-1,0,-2, 0,0,0,-1,1,-1,-1,0,-2,0, 0,0,0,-1,-1,-1,1,0,2,0};
 很黄很暴力吧!!  当时提交成功的时候我都很佩服我自己,这么多数竟然没写错一个。。。。

posted on 2011-08-17 20:06  奋斗青春  阅读(407)  评论(0编辑  收藏  举报