$n) ) { // 範囲外 return; } if ( ($maxtime != -1) && ($maxtime <= $time) ) { // 移動回数多すぎ return; } // ゴール到着 if ( $start == $n ) { $maxtime = $time; return; } if ( isset($visited[$start-1]) === TRUE ) { // 訪問済 if ( $visited[$start-1] <= $time ) { // ルート問わず、高コストで到達してしまった return; } } $visited[$start-1] = $time; $bit = decbin($start); $counts = count_chars($bit, 1); $count = $counts[ord('1')]; $time++; if ( ($start+$count) != $prev ) { move($start, $start+$count, $time); } if ( ($start-$count) != $prev ) { move($start, $start-$count, $time); } return; }