How many ways to express N as sum of 2, 3 and 5?
It looks like you're missing some considerations with respect to the base cases. Since you're starting your for loop at i = 5, you should have base cases set for i = 0, 1, 2, 3, 4. f[0] = 1 since there's 1 way to choose a set of numbers that sums to 0 — choose nothing. f[1] = 0 since there's no way to make 1 out of 2, 3, and 5. f[2] and f[3] are both equal to 1 because they are in your set. Finally, f[4] = 1, since 2+2 = 4. This gives output f[7] = 5, as shown in your example cases. 

For the "harder version", I suggest you look up the coin change problem. The problem formulation is essentially the same — how many ways are there to make up a given sum using a set of coins? The basic idea, and the one that prevents doubly counting permutations of the same solution, is that for each coin or value, you consider whether or not you wish to include it in the current solution set. If so, you get closer to the sum, and you can choose to reuse the same coin/value. If not, the value of your solution stays the same, but you never use that coin/value again in that solution. The final number of ways is just the sum of these two possibilities. Note that this method does have a time complexity of $O(mn)$.

Additional Links

https://www.geeksforgeeks.org/coin-change-dp-7/