// 文字コードはShiftJISを想定 // 反復深化法により解く #include #include using namespace std; struct PIPE { const char *name; // 表示 int connect[2]; // 連結している方向 }; // パイプ const PIPE Pipe[] = { { "□", {-1,-1} }, { "┗", { 0, 1} }, { "┏", { 1, 2} }, { "┓", { 2, 3} }, { "┛", { 3, 0} }, { "┃", { 0, 2} }, { "━", { 1, 3} }, }; // 方向 0:↑ 1:→ 2:↓ 3:← const int Dir[][4] = { {0,-1}, {1,0}, {0,1}, {-1,0} }; // 盤面(短いプログラムなのでグローバルに……) vector > board; int width; int height; int start; int goal; bool Move( int depth ); bool Check(); void Display(); int main() { // 問題 //const char *Q[] = { // "┗┃━┃", // "┏━━┛", // "┃┃┓□" //}; const char *Q[] = { "┗┓┏┛", "┗┓┃━", "┏━┃┃", "┏━┛□", }; width = (int)strlen(Q[0]) / 2; height = sizeof Q / sizeof Q[0]; start = 0; goal = width - 1; // 数値に変換 board.resize( width, vector(height,-1) ); for ( int y=0; y