Recursive Combination Solution using Dynamic Programming

Status
You're currently viewing only euzeka's posts. Click here to go back to viewing the entire thread.
Not open for further replies.
Maybe you could use the fact that comb(n, r) == comb(n, n - r), and transform the "r" parameter on the fly to use the smallest of both values. Don't know if that would really save you something in the end, but I think it might. Try it and see :)

Edit: What I meant:
code:<HR>
Code:
double comb3(int n, int r)
{
    // Your base cases, as before
    if (r > (n / 2))
        r = n - r;
    // the rest stays the same
}
You should also check (at least initially in a wrapper function) that r is valid for the given n. It is often assumed in statistics that the value of this function will be 0 if the input is invalid.
 
Status
You're currently viewing only euzeka's posts. Click here to go back to viewing the entire thread.
Not open for further replies.