Untitled
unknown
plain_text
2 years ago
1.7 kB
5
Indexable
#include<iostream> using namespace std; int arr[7][8]; int check[7][7]; int visit[7][8]; int result; void domino(int x, int y) { if (x == 7) { result++; return; } if (visit[x][y] == 0) { if (y < 7) { if (visit[x][y + 1] == 0) { if (check[arr[x][y]][arr[x][y + 1]] == 0) { check[arr[x][y]][arr[x][y + 1]] = 1; check[arr[x][y + 1]][arr[x][y]] = 1; visit[x][y] = 1; visit[x][y + 1] = 1; if (y + 1 < 7) domino(x, y + 1); else domino (x + 1, 0); check[arr[x][y]][arr[x][y + 1]] = 0; check[arr[x][y + 1]][arr[x][y]] = 0; visit[x][y] = 0; visit[x][y + 1] = 0; } } } if (x < 6) { if (visit[x + 1][y] == 0) { if (check[arr[x][y]][arr[x + 1][y]] == 0) { check[arr[x][y]][arr[x + 1][y]] = 1; check[arr[x + 1][y]][arr[x][y]] = 1; visit[x][y] = 1; visit[x + 1][y] = 1; if (y < 7) domino (x, y + 1); else domino(x + 1, 0); check[arr[x][y]][arr[x + 1][y]] = 0; check[arr[x + 1][y]][arr[x][y]] = 0; visit[x][y] = 0; visit[x + 1][y] = 0; } } } } else { if (y < 7) domino(x, y + 1); else domino (x + 1, 0); } } int main() { int test_case; int T; freopen("input.txt", "r", stdin); cin >> T; /* Read each test case from standard input. */ for(test_case = 1; test_case <= T; ++test_case) { for (int col = 0; col < 7; col++) { for (int row = 0; row < 8; row++) { cin >> arr[col][row]; } } result = 0; domino(0, 0); cout << "#" << test_case << ' ' << result << endl; } return 0;//Your program should return 0 on normal termination. }
Editor is loading...