Hey everyone,
I'm writing a Recursurive solution for doing Combinations using Dynamic Programming and using a apvector (same as a regular vector) as my auxilirary data holder. Here's the code I have so far (works fine, no need to fix):
Now, I showed this to my teacher and he said it was very good except there are a few base cases that I could add that would speed my code up. The thing is, I can't really think of any. If anyone could suggest a few, either in code or in math, that'd be great.
Noah
I'm writing a Recursurive solution for doing Combinations using Dynamic Programming and using a apvector (same as a regular vector) as my auxilirary data holder. Here's the code I have so far (works fine, no need to fix):
code:<HR>Code:apmatrix<double> table(1000,1000,0); double comb3(int n, int r){ if ( n == r || r == 0) return 1; if ( n == 1 || n - r == 1) return n; if (table [n][r] == 0) table[n][r] = comb3(n-1,r - 1) + comb3(n-1,r); return table[n][r]; }
Now, I showed this to my teacher and he said it was very good except there are a few base cases that I could add that would speed my code up. The thing is, I can't really think of any. If anyone could suggest a few, either in code or in math, that'd be great.
Noah