Once upon a time, there was a king who loved beautiful costumes very much. The king had a special cocoon bed to make excellent cloth of silk. The cocoon bed had 16 small square rooms, forming a 44 lattice, for 16 silkworms. The cocoon bed can be depicted as follows:
The cocoon bed can be divided into 10 rectangular boards, each of which has 5 slits:<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PC9wPgo8aW1nIHNyYz0="http://www.Bkjia.com/uploadfile/Collfiles/20131231/20131231094708216.gif" alt="\">
Note that, except for the slit depth, there is no difference between the left side and the right side of the board (or, between the front and the back); thus, we cannot distinguish a symmetric board from its rotated image as is shown in the following:
Slits have two kinds of depth, either shallow or deep. The cocoon bed should be constructed by fitting five of the boards vertically and the others horizontally, matching a shallow slit with a deep slit.
Your job is to write a program that calculates the number of possible configurations to make the lattice. You may assume that there is no pair of identical boards. Notice that we are interested in the number of essentially different configurations and therefore
you should not count mirror image configurations and rotated configurations separately as different configurations.
The following is an example of mirror image and rotated configurations, showing vertical and horizontal boards seperately, where shallow and deep slits are denoted by `1" and `0' respectively.
Notice that a rotation may exchange positions of a vertical board and a horizontal board.
xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx
Each x is either `0' or `1'. `0' means a deep slit, and `1' a shallow slit. A block of five slit descriptions corresponds to a board. There are 10 blocks of slit descriptions in a line. Two adjacent blocks are separated by a space.
For example, the first data set in the Sample Input means the set of the following 10 boards:
The end of the input is indicated by a line consisting solely of three characters ``END"'.
10000 01000 00100 11000 01100 11111 01110 11100 10110 11110 10101 01000 00000 11001 01100 11101 01110 11100 10110 11010 END
40 6
題意:給10塊床坂,求可以拼出的種數,旋轉對稱算一種。
思路:每一塊可以用一個2進制數表示,並且拼圖是不重復的。所以只要開一個32的數組就能存放拼圖了。暴力枚舉。枚舉5塊正放逆放,然後另外5快去判斷能不能組成,一開始想總情況直接除以8,結果一直WA,後面改成用SET保存下找到過的方法的對應的8種方法,就過了。。哎,寫得很搓,卡了兩天了。。
代碼:
#include#include #include #include #include using namespace std; const int zhuan[25] = {20, 15, 10, 5, 0, 21, 16, 11, 6, 1, 22 ,17, 12, 7, 2, 23, 18, 13, 8, 3, 24, 19, 14, 9, 4}; const int dui[25] = {4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 14, 13, 12, 11, 10, 19, 18, 17, 16, 15, 24, 23, 22, 21, 20}; const int N = 20; char str[N], sb[30], sbb[30]; int way[N], ans, save[N], saven, v[32], z[32]; set state; void zh(char *a) { char save[30]; for (int i = 0; i < 25; i ++) save[i] = a[zhuan[i]]; save[25] = '\0'; strcpy(a, save); } void dc(char *a) { char save[30]; for (int i = 0; i < 25; i ++) save[i] = a[dui[i]]; save[25] = '\0'; strcpy(a, save); } int hash(char *s) { int sum = 0; for (int i = 0; i < 5; i ++) if (s[i] == '1') sum = sum * 2 + 1; else sum *= 2; return sum; } void init() { state.clear(); memset(sb, 0, sizeof(sb)); memset(sbb, 0, sizeof(sbb)); memset(v, 0, sizeof(v)); v[hash(str)]++; v[z[hash(str)]]++; for (int i = 1; i < 10; i++) { scanf("%s", str); v[hash(str)]++; v[z[hash(str)]]++; } } bool find(int s) { if (v[s]) { v[s]--; v[z[s]]--; save[saven++] = s; return true; } return false; } bool judge() { for (int i = 4; i >= 0; i --) { int s = 0; for (int j = 0; j < 5; j ++) { if ((way[j] & (1<= 0; i --) { for (int j = 0; j < 5; j ++) { if ((way[j] & (1<= 0; i--) { if (num >= (1<