{
if (size <= 0 || max_step < min_step || min_step >= size)
if (debug)
min_step, max_step);
for (int i = 0; i < size; ++i) {
for (int offset = min_step; offset <= max_step; ++offset) {
DPPoint* prev = offset <= i ? points + i - offset :
NULL;
inT64 new_cost = (points[i].*cost_func)(prev);
if (points[i].best_prev_ !=
NULL && offset > min_step * 2 &&
new_cost > points[i].total_cost_)
break;
}
points[i].total_cost_ += points[i].local_cost_;
if (debug) {
tprintf(
"At point %d, local cost=%d, total_cost=%d, steps=%d\n",
i, points[i].local_cost_, points[i].total_cost_,
points[i].total_steps_);
}
}
int best_cost = points[size - 1].total_cost_;
int best_end = size - 1;
for (int end = best_end - 1; end >= size - min_step; --end) {
int cost = points[end].total_cost_;
if (cost < best_cost) {
best_cost = cost;
best_end = end;
}
}
return points + best_end;
}