Maybe, he meant something like:
(edit: doh, no html in code blocks! I'm sure you can see what I did though, second if statement and second return)
Of course this will not return the same result (you'll have to fiddle with it a bit), so I don't know if this will wind up being faster.
He could have meant "find an earlier occurring base case", which I tried to do. This depends on what garauntees there are on the initial inputs though. . .is a 2x2 matrix valid? Or must it be at least 3x3? Can it be 1x1? 1x3?
code:<HR>Code:apmatrix<double> table(1000,1000,0); double comb3(int n, int r) { if ( n == r || r == 0) return 1; if (n == 2 || n - r == 2) return table[n - 1][r - 1] + table[n - 1][r]; if (table [n][r] == 0) table[n][r] = comb3(n-1,r - 1) + comb3(n-1,r); return table[n][r]; }
(edit: doh, no html in code blocks! I'm sure you can see what I did though, second if statement and second return)
Of course this will not return the same result (you'll have to fiddle with it a bit), so I don't know if this will wind up being faster.
He could have meant "find an earlier occurring base case", which I tried to do. This depends on what garauntees there are on the initial inputs though. . .is a 2x2 matrix valid? Or must it be at least 3x3? Can it be 1x1? 1x3?