A Recursive Algorithm for the Optimal Solution of a Complex Allocation Problem Using a Dynamic Programming Formulation