A problem I'm working on requires me to find the minimum # of integers from a given list that add up to $N$, or more specifically:
Given a list $L$ of $K$ integers, $[a_1, a_2, ... , a_k$], where each $a_{i+1} > a_i$ and each $a_i > 0$, design an algorithm that finds the minimum number of such $a_i$ that their sum adds up to $N$. You can use each $a_i$ an unlimited number of times. You may assume $N$ is a possible sum for any $L$.
Example: $L = [1, 3, 5]$. $N = 10$. The optimal choice is $5 + 5$. A possibility is using $10$ $1$'s, but that is not optimal.
I thought I found the optimal solution using a greedy algorithm, where we start with $0$ add the largest integer from $L$ without going over.
But my greedy algorithm fails in this case:
Integers: $[1, 5, 7]$, $N = 10$; greedy algorithm gives $7+1+1+1$, but optimal solution is $5+5$.
The people I've talked to suggested taking a Dynamic Programming approach, but I am not quite comfortable with DP. What suggestions or hints do you have for thinking of a DP approach? I think I should approach this recursively, but in what way? Should I keep breaking it down to halves until I find individual components (kinda like mergesort), and see what numbers these components add up to in $L$?