Dynamic programming arithmetical design patterns.