From Your question, I understood that you are having confusion between DP and the Greedy approach.
DP--Taking intuition about Dp, actually Dp is the approach in which we check for all possible solutions which can be a contestant for the actual solution, we select anyone from it. But the thing that makes Dp different is the overlapping subproblem. Now, what is the overlapping subproblem - suppose we have to calculate the sum of all numbers from 1 to 7, we find the answer by doing 1+2+3+4+5+6+7 and store that answer, Now we have to calculate sum from 1 to 10, now what we will do 10+9+8+ans(7) this means we have reduced our efforts of doing the same thing which we have done before. This has drastically reduced our time. So actually this is DP. Whether we apply recursion or iterative we have to store past results. So actually saying about DP, it is recursion + remembering the past answers.
Now telling about Greedy - In greedy, we don't check for every possibility, we find the answer on the basis of the previously found optimal solution, but don't check about every possibility.
This concept will get more and more clear once you will solve a sufficient amount of questions on both topics.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…