If you update state at each step then you can't share state easily.
when i start processing the position N+len, i need the state[N+len] that's copy of state[N] plus the match(len,dist). instead of copying the state structure, i modify it, use to check all possible matches starting in this position, and then return back to original state. no sharing is required since we use only one state at the time
look at bold vars:
Code:
for pos in (0..N)
state[pos] := state[best_prev_pos[pos]], updated for a best_match[pos]
for (len,dist) in possible_matches[]
match_price = state[pos].price(len,dist)
if price[pos]+match_price < price[pos+len]
price[pos+len] = price[pos]+match_price
best_prev_pos[pos+len] = pos
best_match[pos+len] = (len,dist)
// here we undo the state changes