python,dynamic-programming,memoization,python-decorators,coin-change

In your current code: def memo(fn): def helper(*args): d = {} you create a new "cache" dictionary d every time the decorated function is called. It's no wonder it's slower! The minimal fix is: def memo(fn): d = {} def helper(*args): but it could be neater generally. I use: def...

dynamic-programming,coin-change

You're making piles of coins for different values j, named M(j). The point of M(j - vi) is to consider a coin of value vi, then which pile do you add it to in order to reach the value j? The pile with value j - vi of course, because...

algorithm,dynamic-programming,coin-change

Lets first talk about the number of ways, DP(m,n) = DP(m-1, n) + DP(m, n-Sm). This in indeed correct because either you can use the mth denomination or you can avoid it. Now you say why don't we write it as DP[i] = DP[i-d1]+DP[i-d2]+...DP[i-dn]. Well this will lead to...