小编use*_*735的帖子

用于计算组合数的递归方法

这是一个java代码,以递归方式计算特定硬币的支付数量(例如,1,2,5,20,50等).我试图找出它是如何工作但似乎无法得到它.有人可以这么善良并解释代码背后的数学和逻辑以及这种递归是如何工作的吗?我真的很感激.

    // Returns the count of ways we can sum  S[0...m-1] coins to get sum n
int count( int S[], int m, int n ){

    // If n is 0 then there is 1 solution (do not include any coin)
    if (n == 0)
        return 1;

    // If n is less than 0 then no solution exists
    if (n < 0)
        return 0;

    // If there are no coins and n is greater than 0, then no solution exist
    if …
Run Code Online (Sandbox Code Playgroud)

java recursion

4
推荐指数
1
解决办法
2219
查看次数

标签 统计

java ×1

recursion ×1