To follow up blockhead's advice about dynamic programming, you
might also want to look at greedy algorithms.
A greedy algorithm breaks a problem down into recursive subproblems just like dynamic programming does, but it picks the best solution at each level before moving on to the subproblem.
It's like making change for 47c. A quarter is the largest coin that fits in a 47c 'hole'. That leaves 22c. A dime is the largest coin that fits in a 22c 'hole'. That leaves 12c. By the same process, we get another dime and two pennies.
Greedy algorithms perform well on average, but they do not guarantee an optimal solution every time.
If we tried the above experiment with coins worth 35c, 30c, and 15c, the greedy algorithm would tell us that a single 35c coin is the best match.
But in fact, a 30-15 combination would get us closer to 47c.
If you want to guarantee an optimal solution, you need to use dynamic programmming.
If you're willing to tolerate imperfect solutions, or you know that your pieces are partitioned well enough to solve any problem, you can use greedy algorithms.