#include #include #include std::vector m; std::vector d; int n; void move(int now, int count) { if (count >= d[now-1] && d[now-1] != -1) { return; } else { d[now-1] = count; } if (now == 1) { return; } for (int i = 0; i < n; i++) { if (abs(now - i - 1) == m[i]) { move(i+1, count+1); } } } int main() { std::cin >> n; d.clear(); d.resize(n, -1); m.clear(); m.resize(n, 0); // (i+1) -> binary としたときの1の数 std::vector f(n, false); // 到達したらtrue for (int i = 0; i < n; i++) { int tmp = i + 1; while (tmp != 0) { if (tmp % 2 == 1) { m[i]++; } tmp /= 2; if (m[tmp-1] != 0) { m[i] += m[tmp-1]; break; } } } move(n, 1); std::cout << d[0] << std::endl; }