vector<int> temp, op, after; bool first = true; for (int i = 0; i < target.size(); ++i) op.push_back(i + 1); while(op.size()) { for (int i = 1; i < op.size(); i += 2) { temp.push_back(op[i]); } for (int i = 0; i < op.size(); i += 2) { temp.push_back(op[i]); } // first step
op = temp; temp.clear(); if (first && op == target) returntrue; first = false;
for (int i = 0; i < min(maxK, (int)op.size()); ++i) after.push_back(op[i]); if (op.size() > maxK) op.erase(op.begin(), op.begin() + maxK); else op.clear(); }