#include<iostream> #include<cstdio> #include<cstring> #define db(a) cout << #a << " = " << a << endl using namespace std; int matriz[6][6]; int prev12[] = {1, 2, 3, 5}; int prev35[] = {1, 2, 3, 4, 5}; int prev4[]= {3, 5}; void buscar(int res,int deep) { if(deep == 8) { //printf("%d %d\n",cont++, res); printf("%d\n", res); } else { int prev = res % 10; if (prev == 1 || prev == 2) { for (int i = 0; i < 4; i++) { if (!matriz[prev][prev12[i]]) { matriz[prev][prev12[i]] = 1; matriz[prev12[i]][prev] = 1; /*db(prev); db2(res * 10 + prev12[i], deep + 1);*/ buscar(res * 10 + prev12[i], deep + 1); matriz[prev][prev12[i]] = 0; matriz[prev12[i]][prev] = 0; } } } else { if (prev == 3 || prev == 5) { for (int i = 0; i < 5; i++) { if (!matriz[prev][prev35[i]]) { matriz[prev][prev35[i]] = 1; matriz[prev35[i]][prev] = 1; /*db(prev); db2(res * 10 + prev35[i], deep + 1);*/ buscar(res * 10 + prev35[i], deep + 1); matriz[prev][prev35[i]] = 0; matriz[prev35[i]][prev] = 0; } } } else { for (int i = 0; i < 2; i++) { if (!matriz[prev][prev4[i]]) { matriz[prev][prev4[i]] = 1; matriz[prev4[i]][prev] = 1; /*db(prev); db2(res * 10 + prev4[i], deep + 1);*/ buscar(res * 10 + prev4[i], deep + 1); matriz[prev][prev4[i]] = 0; matriz[prev4[i]][prev] = 0; } } } } } } int main() { memset(matriz, 0, sizeof matriz); for (int i = 0; i < 6; i++) matriz[i][i] = 1; buscar(1, 0); return 0; }
jueves, 27 de octubre de 2011
291 - The House Of Santa Claus, uva
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario