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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
| // // main.cpp // ZOJ2669 // // Created by zhangmin chen on 2019/7/7. // Copyright © 2019 zhangmin chen. All rights reserved. //
using namespace std; typedef long long llong; typedef set<string>::iterator ssii;
const int maxn = 10; const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
class Grid { public: int x, y; Grid(int _x = 0, int _y = 0) : x(_x), y(_y) {} bool operator< (const Grid& rhs) const { return x < rhs.x || (x == rhs.x && y < rhs.y); } };
typedef set<Grid> Post; set<Post> depth[maxn + 1]; // depth begin from [1, n] int ans[maxn + 5][maxn + 5][maxn + 5];
int n, w, h;
void init() { Set(ans, 0); _for(i, 0, maxn) depth[i].clear(); }
void init2() { Post beg; beg.insert(Grid(0, 0)); depth[1].insert(beg); }
// from depth 1, then expand the solution tree
Post normalize(const Post& p) { Post p2; int minX = inf, minY = inf; for(auto& grid : p) { minX = min(minX, grid.x); minY = min(minY, grid.y); } for(auto& grid : p) { p2.insert(Grid(grid.x - minX, grid.y - minY)); } return p2; }
Post _rotate(const Post& p) { Post p2; for(auto& grid : p) { p2.insert(Grid(grid.y, -grid.x)); } return normalize(p2); }
Post _flip(const Post& p) { Post p2; for(auto& grid : p) { p2.insert(Grid(grid.x, -grid.y)); } return normalize(p2); }
// in dfs, if d == maxd, try to insert // posture to depth[d] bool tryInsert(Post p, int d) { _for(i, 0, 4) { p = _rotate(p); if(depth[d].count(p)) return false; } p = _flip(p); _for(i, 0, 4) { p = _rotate(p); if(depth[d].count(p)) return false; } depth[d].insert(p); return true; }
// void dfs(Post p, int d, int maxd) { if(d == maxd) { tryInsert(p, d); return; } for(auto grid : p) _for(dir, 0, 4) { Grid nxtG(grid.x + dx[dir], grid.y + dy[dir]); if(!p.count(nxtG)) { Post p2 = p; p2.insert(nxtG); dfs(p2, d+1, maxd); } } }
void bfs(int d, int maxd) { queue<Post> que; for(auto p : depth[d]) que.push(p); while (!que.empty()) { Post f = que.front(); que.pop(); if(f.size() == maxd) { tryInsert(f, maxd); continue; } for(auto grid : f) _for(dir, 0, 4) { Grid nxtG(Grid(grid.x + dx[dir], grid.y + dy[dir])); if(!f.count(nxtG)) { Post p2 = f; p2.insert(nxtG); if(p2.size() <= maxd) que.push(p2); } } } }
void printTable() { // init(); init2(); /* _rep(maxd, 2, maxn) for(auto p : depth[maxd - 1]) dfs(p, maxd - 1, maxd); */ _rep(maxd, 2, maxn) bfs(maxd - 1, maxd); _rep(n, 2, maxn) _rep(w, 1, maxn) _rep(h, 1, maxn) { int cnt = 0; for(auto p : depth[n]) { int maxX = 0, maxY = 0; for(auto grid : p) { maxX = max(maxX, grid.x); maxY = max(maxY, grid.y); } if(min(maxX, maxY) < min(w, h) && max(maxX, maxY) < max(w, h)) cnt++; } ans[n][w][h] = cnt; //debug(ans[n][w][h]); } //for(auto g : depth[1]) for(auto p : g) cout << p.x << " " << p.y << endl; }
int main() { freopen("input.txt", "r", stdin); printTable(); while (scanf("%d%d%d", &n, &w, &h) == 3) { // solve() if(n == 1) { printf("1\n"); continue; } printf("%d\n", ans[n][w][h]); } }
|