Yeah, it is a very typical problem. Maybe when I studied dynamic programming, I was restricted my mind within some "optimal" solution questions. Most time the examples are talking about how to change money with minimal number of coins. Actually I sought in google, I got the answer and source code, but still don't understand why. ;)
【在 c****t 的大作中提到】 : a very typical problem using dynamic programming. Search "coin changing" : "dynamic programing" in google.
r*d
4 楼
设f1为只能用1 cent 的换法 f1(a)=1 for all a>=0; 设f2为可以用5 cent, 1 cent 的换法 f2(a)=f1(a)+f1(a-5)+f1(a-10)+...=sum( f1(a-i*5)) for all i,i>=0; i*5<=a 设f3为可用10,5,1,cent 的换法数 f3=f2(a)+f2(a-10)+...=sum (f2(a-i*10)) 0<=i<=i/10; ...