利用打表法,首先将所有的情况全部计算出来,然后直接查表就可以了。所谓的旋转翻转其实都可以转化为原来位置依次旋转90度以及先翻转得到新的状态,然后依次旋转90度就行了。具体实现见如下代码:
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
using namespace std;
int n, w, h;
int result[11][11][11];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
struct node{
int x, y;
node(int x1 = 0, int y1 = 0){
x = x1; y = y1;
}
bool operator< (const node& a) const{
if (x != a.x) return x < a.x;
return y < a.y;
}
};
typedef set<node> polygon;
set<polygon> arr[11];
void Normalize(polygon& b){
int minX = b.begin()->x, minY =b.begin()->y;
for (polygon::iterator it = b.begin(); it != b.end(); it++){
minX = min(minX, it->x);
minY = min(minY, it->y);
}
polygon b2;
for (polygon::iterator it = b.begin(); it != b.end(); it++){
b2.insert(node(it->x - minX, it->y - minY));
}
b = b2;
}
void Flip(polygon& b){
polygon b2;
for (polygon::iterator it = b.begin(); it != b.end(); it++){
b2.insert(node(it->x,-(it->y)));
}
Normalize(b2);
b = b2;
}
void Rotate(polygon& b){
polygon b2;
for (polygon::iterator it = b.begin(); it != b.end(); it++){
b2.insert(node(it->y,-(it->x)));
}
Normalize(b2);
b = b2;
}
void check(int index, polygon b, node a){
b.insert(a);
Normalize(b);
for (int i = 0; i < 4; i++){
if (arr[index].find(b) != arr[index].end()) return;
Rotate(b);
}
Flip(b);
for (int i = 0; i < 4; i++){
if (arr[index].find(b) != arr[index].end()) return;
Rotate(b);
}
arr[index].insert(b);
}
void get_Result(){
polygon first;
first.insert(node(0,0));
arr[1].insert(first);
for (int i = 2; i <= 10; i++){
for (set<polygon>::iterator it = arr[i - 1].begin(); it != arr[i - 1].end(); it++){
for (polygon::iterator it2 = (*it).begin(); it2 != (*it).end(); it2++){
for (int j = 0; j < 4; j++){
node b(it2->x+dx[j],it2->y+dy[j]);
if (it->find(b) == it->end()){
check(i, *it, b);
}
}
}
}
}
for (int i = 1; i <= 10; i++){
for (int j = 1; j <= 10; j++){
for (int k = 1; k <= 10; k++){
int amount = 0;
for (set<polygon>::iterator it = arr[i].begin(); it != arr[i].end(); it++){
int maxX=0, maxY=0;
for (polygon::iterator it2 = it->begin(); it2 != it->end(); it2++){
maxX = max(maxX, it2->x); maxY = max(maxY, it2->y);
}
if (min(maxX, maxY) < min(j, k) && max(maxX, maxY) < max(j, k)) amount++;
}
result[i][j][k] = amount;
}
}
}
}
int main(){
get_Result();
while (cin >> n >> w >> h){
cout << result[n][w][h]<<endl;
}
return 0;
}