Dynamic programming - circuit routing code