DP:换钱的总方法数

public static int test5(int[] ary,int aim) {
        if (ary==null||ary.length==0||aim<0) {
            return -1;
        }
        return coin(ary, 0, aim);
        
    }
    
    public static int coin(int[] ary,int index,int aim) {
        int res = 0;
        if (index==ary.length) {
            res = aim==0?1:0;
        } else {
            for (int i = 0; i*ary[index] <= aim; i++) {
                res+=coin(ary, index+1, aim-i*ary[index]);
            }
        }
        return res;
    }

你可能感兴趣的:(DP:换钱的总方法数)