-Vijju
On 11/6/06,
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Nice hint indeed! The code finish in 0.02s taking in account that some
sums repeats! Thanks for the hint really! I feel so dumb to not think
about that before :-(
Anyway, the renewed function looks like :
=========================
unsigned cache[80][80] = {0};
#define CACHED(i,j)\
if (!cache[i][j])\
cache[i][j] = sum(i,j);
unsigned sum(int i, int j) {
if (i == 79 && j == 79) {
return matrix[i][j];
} else if (j == 79 && i != 79) {
CACHED(i+1,j);
return matrix[i][j] + cache[i+1][j];
} else if (i == 79 && j != 79) {
CACHED(i, j+1);
return matrix[i][j] + cache[i][j+1];
}
CACHED(i,j+1);
CACHED(i+1,j);
if (cache[i+1][j] > cache[i][j+1])
return matrix[i][j] + cache[i][j+1];
else
return matrix[i][j] + cache[i+1][j];
}
=========================
thank you very much!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups-beta.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---