Untitled

unknown
plain_text
a year ago
2.2 kB
0
Indexable
Never
```#include<iostream>
using namespace std;
#pragma warning(disable:4996)
#define H 0
#define	V 1
int a[7][8];
int visited[7][8];
int F[7][7];
int n = 7, m = 8;

int ans;
void Try(int x, int y) {
//cout << endl;
if (x == n) {
ans++;
return;
}

if (!visited[x][y]) {
if ((y + 1) < m && !visited[x][y + 1] ) {
if (a[x][y] <= a[x][y + 1] && F[a[x][y]][a[x][y + 1]]) {
visited[x][y] = visited[x][y + 1] = 1;
F[a[x][y]][a[x][y + 1]] = 0;

if (y < m - 1) Try(x, y + 1);
else Try(x + 1, 0);
visited[x][y] = visited[x][y + 1] = 0;
F[a[x][y]][a[x][y + 1]] = 1;

}
else if (F[a[x][y + 1]][a[x][y]]) {
visited[x][y] = visited[x][y + 1] = 1;
F[a[x][y+1]][a[x][y]] = 0;

if (y < m - 1) Try(x, y + 1);
else Try(x + 1, 0);
visited[x][y] = visited[x][y + 1] = 0;
F[a[x][y+1]][a[x][y]] = 1;

}
}

if ((x + 1) < n && !visited[x+1][y]) {
if (a[x][y] <= a[x + 1][y] && F[a[x][y]][a[x + 1][y]]) {
visited[x][y] = visited[x + 1][y] = 1;
F[a[x][y]][a[x + 1][y]] = 0;

if (y < m - 1) Try(x, y + 1);
else Try(x + 1, 0);
visited[x][y] = visited[x + 1][y] = 0;
F[a[x][y]][a[x + 1][y]] = 1;

}
else if(F[a[x+1][y]][a[x][y]]) {
visited[x][y] = visited[x + 1][y] = 1;
F[a[x+1][y]][a[x][y]] = 0;

if (y < m - 1) Try(x, y + 1);
else Try(x + 1, 0);
visited[x][y] = visited[x + 1][y] = 0;
F[a[x+1][y]][a[x][y]] = 1;

}
}
//cout << x << " -!!!- " << y << endl;

}
else {
//cout << x << " +++ " << y << endl;
if (y < m-1) Try(x, y + 1);
else Try(x + 1, 0);
}

}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
F[i][j] = 1;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
visited[i][j]=0;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}

ans = 0;
Try(0, 0);
cout <<"#"<<t<<" "<<ans<< endl;
}

return 0;
}```