1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #include <iostream> #include <string.h> #include <map> #include <algorithm>
using namespace std;
const int w = 3,h = 10; int e[w][h]; int ans;
map<int,int> Hash;
bool check() { for (int i=0; i<w; i++) for (int j=0; j<h; j++) if (i+1 < w && j+1 < h) if ( (e[i][j] + e[i+1][j] + e[i][j+1] + e[i+1][j+1]) % 4 == 0 ) return false; return true; } void fill(int x,int y) { if (e[x][y] == -1) { if (y+1 < h && e[x][y+1] == -1) {
for (int i=0; i<2; i++) { e[x][y] = e[x][y+1] = i; if (y == h-1) fill(x+1,0); else fill(x,y+1); e[x][y] = e[x][y+1] = -1; } } if (x+1 < w && e[x+1][y] == -1) {
for (int i=0; i<2; i++) { e[x][y] = e[x+1][y] = i; if (y == h-1) fill(x+1,0); else fill(x,y+1); e[x][y] = e[x+1][y] = -1; } } } else { if (x == w-1 && y == h-1) { if ( check() ) { int res = 0; int bit = 1; for (int i=0; i<w; i++) for (int j=0; j<h; j++) { res += e[i][j] * bit; bit *= 2; } if ( !Hash.count(res) ) { Hash[res] = 1; ans++; } } return ; } if (y == h-1) fill(x+1,0); else fill(x,y+1); } return ; } int main() { memset( e, -1, sizeof e); fill(0,0); cout << ans; return 0; }
|