Dynamic programming fixed

Someone changed the dynamic programming so that it malfunctioned.
Discovered this when investigating Chris' issue of numerical matching.