|
|
发表于 2012-2-3 10:27:27
|
显示全部楼层
最土的办法,递归:
设数组int index[8]={1,2,5,10,20,50,100,200};表示每种钱币的面值大小。
函数int f( int*index, int begin, int end, int total );返回用index[begin...end]这么多种钱币表示总数为total的钱有集中表示方法,得到递归公式:
f( index, begin, end, total ) = f( index, begin, end, total-index[begin] ) + f( index, begin+1, end, total );//意思是如果取一个index[begin]的话,表示方法数目等于
//f( index, begin, end, total-index [begin] );
//不取index[begin]的话,表示方法数目等于 f( index, begin+1, end, total );
在加上递归结束条件:
begin>end,f=0;
total<=0,f=0
知道怎么递归了吧? |
|