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
|
#include <iostream>
struct edge{
int to_where, *directions;
};
int directions[] = {2, 2, 2, 2, 1, 1};
edge states[][3] = {
{{1, directions + 0}, {2, directions + 4}, {3, directions + 1}},
{{0, directions + 0}, {2, directions + 2}, {3, directions + 5}},
{{0, directions + 4}, {1, directions + 2}, {3, directions + 3}},
{{0, directions + 1}, {1, directions + 5}, {2, directions + 3}},
};
bool backtracking(int state){
for (int i = 0; i < 3; i++){
edge &e = states[state][i];
if (!*e.directions)
continue;
--*e.directions;
if (backtracking(e.to_where))
return 1;
++*e.directions;
}
//Edited on 2014-09-18:
//This part of the proof is incorrect. There's no way for backtracking() to
//return anything other than false.
//return 0;
//Here's the correction:
for (int i = 0; i < 6; i++)
if (directions[i])
return 0;
return 1;
}
bool backtracking(){
for (int i = 0; i < 4; i++)
if (backtracking(i))
return 1;
return 0;
}
int main(){
std::cout <<backtracking()<<std::endl;
}
| |